CHAPTER 9Using Regular Expressions

Sometimes when you are processing strings, you will run into a problem that is difficult to solve with strcomp or other functions. For instance, you might have to validate an e-mail address, which requires you to look at many difficult-to-check rules.

This is where regular expressions come in handy. Regular expressions are powerful, concise groups of characters that can contain quite a bit of logic, especially considering how short they are.

Think of regular expressions as mathematical expressions that work on strings. Like mathematical expressions, regular expressions have certain characters that mean something special. Like + says "plus" in a mathematical expression, a character such as ^ says "the beginning ...

Get PHP 5 Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.