Regular Expressions Notes 
. matches any one character
[] character class, matches one character; gr[ae]y matches gray or grey
[^] matches any character not listed.

[1-6] is the same as [123456], which matches any number from 1 to six
[^0-9a-fA-F] is the same as [^0123456abcdefABCDEF], wich matches any character NOT hexadecimal

^ matches start of line
$ matches end of line
\b marches word boundaries

| logic OR, matches either expression it separates, second|2nd matches second or 2nd
() expression grouping, gr(a|e)y matches gray or grey

? matches one optional, Angela? matches Angel and Angela
* matches any amount OK, a*
+ matches at least one, a+

{0,1} the same as ?, a{0,1} the a is optional
{0,10} minimum zero, maximum ten; a{0,10}
{5,8} minumum five, maximum eight.



// Greedy quantifiers
String match = find("A.*c", "AbcAbc"); // AbcAbc
match = find("A.+", "AbcAbc"); // AbcAbc

// Nongreedy quantifiers
match = find("A.*?c", "AbcAbc"); // Abc
match = find("A.+?", "AbcAbc"); // Abc

// Look arounds
//positive lookahead: match Cent only if followed by OS
Cent(?=OS)

// negative lookahead: match Cent only if not followed by OS
Cent(?!OS)

// postive lookbehind: match OS only if preceded by Cent
(?<=Cent)OS

// negative lookbehind: match OS only if not preceded by Cent
(?<!Cent)OS


----------------------------------------------------------------------------------
See:
http://www.pcre.org/pcre.txt
http://www.php.net/manual/en/intro.pcre.php

Comments
Comments are not available for this entry.
2024 By Angel Cool