Any recommendations, as I need to learn regular expressions to search for specific string and replace using specific operators. I have looked at the php functions such as preg_match && preg_replace and understood how they work but all I need is to be more familiar with the operators for expressions. Thanks.
views:
172answers:
6learn perl regular expressions as they are universal and you can use them in PHP as well.
PHP supports two sets/libraries, the first is Perl compatible regular expressions or PCRE, which are more modern and practical in use ( preg
functions ) as opposed to the POSIX Extended Regular Expressions "standard" which is a tad outdated/ more bare-bones ( ereg
functions ) compared to PCRE.
I would recommend going through the perlre tutorial, either use Perl or substitute the Perl methods with PHP ones. Of course Perl Regex engine is more advanced/up to date than the one in the PHP PCRE engine, but the core is pretty much the same.
If you really would like to purchase a book then I would recommend:
The first being more of a cookbook and is relatively new, the second is the definitive guide on regular expressions and covers them in various PCRE implementations and languages.
Good utilities for testing them live/online:
References:
regular-expressions.info is pretty good too, the quickstart guide is useful. Though can be a little complex
W3Schools is also a good place to look, has a nice list of operators.
http://www.regular-expressions.info that's where i started.... might want to use a regex testing tool too
There is no such thing as PHP regular expressions =P There exists Perl-Compatible and POSIX Extended regular expressions in PHP.
A search on Amazon for regular expressions would list:
- Mastering Regular Expressions
- Regular Expressions Cookbook
in that order. Those books are the only books you´ll ever need in this subject.
I'd recommend checking out this site
http://www.gskinner.com/RegExr/
I like it, because you can immediately see what your regular expression matches as you type.