A general and thorough exploration of Regex. Starts with the theory and basic implementation and dives into numerous examples. Covers everything from character sets through lookarounds and conditionals.
of symbols, you can create an infinite set of strings (Kleene Closure) using those symbols. Any arbitrary subset of these strings (a language) cannot be determined by computing. However, they may be defined.
can also use alternation with literals Special characters mean something special , , Escape special character to use Its easy to define ranges, or character classes , abc 158 cat|dog + - [] \+ [a-z] [0-9]
windows) is tab is whitespace (and maybe ) is word character is word boundary (zero-length) is digit Capitalize to negate ( matches !digit) \n \r \t \s [ \t\f] [\r\n] \w [A-Za-z0-9_] \b \d \D
for limiting quantifiers or alternations If you need a group but don't want it captured, Alternation can spawn multiple captures, use You can also name groups with () (?: (?| (?P<name>pattern)
to match everything, including newlines ignores whitespace in pattern (so it can breathe more) evaluates the code (deprecated, don't do this!) Many more on i m ^ $ s . x e PHP's PCRE page
end of patterns Lookaheads are and Lookbehinds are and More complex Lookbehinds only support fixed width, no quantifiers Workaround (in some languages) is (?= (?! (<?<= (?<! /\b(?=[a-z]+\b)[a-z]*(nike|viagra|nfl)[a-z]*/ \K
pull code and date out H T T P / 1 . x 2 0 0 O K D a t e : S a t , 2 8 N o v 2 0 0 9 0 4 : 3 6 : 2 5 G M T E x p i r e s : S a t , 2 8 N o v 2 0 0 9 0 5 : 3 6 : 2 5 G M T /(?:(HTTP)\/\d.[a-z]|(Date|Expires):) (?(1)(\d+)|([A-Za-z ,\d:]+))/
matches (by reference), flags, offset p r e g _ m a t c h ( ' / < a h r e f = " ( ? P < l i n k > [ ^ " ] + ) " ( ? : t i t l e = " ( ? P < t i t l e > [ ^ " ] + ) " ) ? > ( ? P < a n c h o r > [ ^ < ] + ) < \ / a > / ' , ' < a h r e f = " u r l " t i t l e = " s e o t i t l e " > s e o a n c h o r < / a > ' , $ m a t c h e s ) ; { [ 0 ] = > s t r i n g ( 4 6 ) " < a h r e f = " u r l " t i t l e = " s e o t i t l e " > s e o a n c h o r < / a > " , [ " l i n k " ] = > s t r i n g ( 3 ) " u r l " , [ 1 ] = > s t r i n g ( 3 ) " u r l " , [ " t i t l e " ] = > s t r i n g ( 9 ) " s e o t i t l e " , [ 2 ] = > s t r i n g ( 9 ) " s e o t i t l e " , [ " a n c h o r " ] = > s t r i n g ( 1 0 ) " s e o a n c h o r " , [ 3 ] = > s t r i n g ( 1 0 ) " s e o a n c h o r " , }
returns modified subject preg_filter() will return null or empty array on failure can accept strings or arrays for replacements and strings preg_replace_callback() accepts a callback (awesome)