Thursday, March 27, 2014

Regular Expressions Reference Card


Title Reference Explanation Example Matches
Letters Inside Square Brackets [Ww] W or w [Ww]oodwork Woodwork, woodwork

[1234567890] Any digit






Letters outside square brackets ame Matches exact sequence ame -> amersohail794 matches ame





Ranges [0-9] 0 to 9 [0-2] -> amersohail794 matches 794

[a-z] all characters from a to z [a-z] -> amersohail794 matches amersohail

[A-Z] all characters from A to A [a-z] -> amersohail794 matches nothing

[ ] matches space [] -> amer sohail matches space only





Not [^a-z] Not characters from a-z [^a-z] matches 794

[^a-aA-Z] Not characters from a-z and from A-Z [^a-zA-Z] -> amersohail794 matches 794





Beginning of line ^ carret outside the square bracket shows that following character should be matched beginning of the line ^o -> oooohhhh OOOOhhh oooOOOOHHHH will match to first character only and that is "o"





End of line $ $ will match end of the line






Pipe Symbol | for or. A|a is same as [aA] W|w matches W or w





Special Characters *  0 or more occurences of previous character o*O*h*  matches oohhh, ooooooooohhhhh,OOOOOhhhhhh,oooOOOOOhhhhh

+ 1 or more occurences of previous character


? 0 or 1 occurrence of previous character


. Any character


\ is used as escape character [\.] -> This is sample sentence. will match the . In the line

No comments: