PHP has two sets of regular expression functions: the ereg and preg functions. The preg functions support a modern full-featured regex syntax based on the PCRE library and are recommended for new code. Since PHP 7.3.0 they are based on PCRE2.
The ereg functions implement POSIX regular expressions which offer a limited syntax. The ereg functions are deprecated, but RegexBuddy still fully supports them so you can maintain existing code or convert your regular expressions from PHP’s ereg flavor to the preg flavor.
First, use RegexBuddy to define a regex or retrieve a regexp saved in a RegexBuddy library. Rely on RegexBuddy’s clear regex analysis, which is constantly updated as you build the pattern, rather than dealing with the cryptic regex syntax on your own. Detailed help on that syntax is always only a click away.
If you copied a regex written for another programming language, simply paste it into RegexBuddy, select the original language, and then convert the regex to the specific version of PHP and the set of functions you’re using. You can also convert from one version of PHP to another, and from the old ereg syntax to the modern preg syntax. If you’re writing a code library that needs to work with multiple versions of PHP, compare your regex between those PHP versions to make sure it will work exactly the same with all of them. RegexBuddy knows all the features and all the bugs in all versions of PCRE from 2003’s PHP 4.3.3 all the way to the latest PHP 8.1.24.
If you created a new regular expression, test and debug it in RegexBuddy before using it in your PHP source code. Test each regex in RegexBuddy’s safe sandbox without risking precious data. Quickly apply the regex to a wide variety of input and sample data, without having to produce that input through your script.
Finally, let RegexBuddy generate a source code snippet that you can copy and paste directly into whichever IDE or PHP code editor you use. Just choose what you want to use the regex for, and a fully functional code snippet is ready. You can change the names of variables and parameters to suit your naming style or the current situation, which RegexBuddy automatically remembers.
Don’t bother trying to remember which methods to call or which parameters to pass. And don’t worry about properly escaping backslashes and quotes. Just tell RegexBuddy what you want to do, and you will get the proper PHP code straight away. Anything can be done: testing a string for a match, extracting search matches, validating input, search-and-replace, splitting a string, etc.