Adding Comments preg_match("/^ (1[-\s.])? # optional '1-', '1.' or '1' ( \( )? # optional opening parenthesis \d{3} # the area code (?(2) \) ) # if there was opening parenthesis, close it [-\s.]? # followed by '-' or '.' or space \d{3} # first 3 digits [-\s.]? # followed by '-' or '.' or space \d{4} # last 4 digits $/x",$number); Let’s put it within a code segment. $numbers = array( "123 555 6789", "1-(123)-555-6789", The trick is to use the ‘x’ modifier at the end of the regular expression . It causes the whitespaces in the pattern to be ignored, unless they are escaped (\s). This makes it easy to add comments. Comments start with ‘#’ and end at a newline. Greedy vs. Ungreedy Before I start explaining this concept, I would like to show an example first. Let’s say we are looking to find anchor tags in an html text: $html = 'Hello World! '; if (preg_...
I am a PHP programmer, i have strong knowledge of various technologies like Web 2.0, LAMP , SAAS, WAAS.