10 Number-based Examples for Deciphering PHP Regular Expressions

by Jason Gilmore

PHP regular expression syntax can be almost indecipherable. Using these 10 examples, you can construct even complex PHP regular expressions with ease.

PHP regular expression syntax is almost as indecipherable as the United States tax code, prompting the programmer to consult a manual almost automatically every time he or she needs to perform a particularly complex parsing task. If you're one of those programmers who would like to decipher the mish-mash of backslashes, brackets, asterisks and other characters that somehow can root out everything from email addresses to HTML tags, Jason Gilmore has written a PHPBuilder.com tutorial just for you. He introduces PHP regular expressions using 10 numerically-oriented examples.

  1. Finding digits
  2. Finding groups of digits
  3. Filtering unwanted strings
  4. Expanding your range
  5. Increasing your selectivity
  6. Finding more complex patterns
  7. Accounting for inconsistency
  8. Correcting errors
  9. Taking advantage of alternative syntax
  10. Avoiding regular expressions

With these examples and some practice, constructing even complex regular expressions will become as natural as riding a bicycle.

Read the full story at PHPBuilder:
10 Easy Examples for Deciphering PHP Regular Expressions

This article was originally published on Wednesday Jul 21st 2010
Mobile Site | Full Site