Mal wieder Reguläre Ausdrücke
Ich mag Reguläre Ausdrücke und in dem Posting Advanced Regular Expression Tips and Techniques gab es auch einige Dinge die ich nicht mehr auf dem Schirm hatte.
(?(condition)true-pattern|false-pattern)or(?(condition)true-pattern)
For example we can use this to check for opening and closing angle brackets:
$pattern = '/^(<)?[a-z]+(?(1)>)$/';In the example above, ‘1′ refers to the subpattern (<), which is also optional since it is followed by a question mark. Only if that condition is true, it matches for a closing bracket.
‘non-capturing’ Subpatterns:
preg_match('/(?:H.*) (f.*)(b.*)/', 'Hello foobar', $matches);By adding ‘?:’ at the beginning of the subpattern, we no longer capture it in the $matches array.

