With this blog I intend to give you my perspective about various technology related stuff. I've remained a layman for a long time, so I hereby give you a very simple view of how things look to me and how to implement new ideas in a simple manner

Tuesday, June 30, 2009

One of the most essential things you need to know as a software engineer or as a software engineering student is regular expressions. This post will brief you about the basics of regular expressions, again remember this is just a layman's view and not a geeks perspective, so read this and move on.....

Metacharacters -------------------------Matches

. -------------------------------Anything except newline character

\n -----------------------------Newline

* ------------------------------Zero or more copies of preceding expression

+ -----------------------------One or more occurrence of preceding expression

? ------------------------------Zero or one copies of preceding expression

^ -----------------------------Beginning of a line

$ ------------------------------End of line

a|b ---------------------------a or b

(ab)+ -----------------------One or more copies of ab (grouping)

"a+b" -----------------------Literal "a+b"

[] ------------------------------Character class

Examples :-

abc------------------------------------- abc

abc* -----------------------------------ab abc abcc abcc abccc ......

abc+ ----------------------------------abc abcc abccc.....

a(bc)+ -------------------------------abc abcbc abcbcbc....

a(bc)? --------------------------------a abc

[abc] ----------------------------------one of:a,b,c

[a-z] -----------------------------------any letter, a-z

[a\-z] ----------------------------------one of : a,-,z

[-az] ---------------------------------- one of : - , a, z

[a-zA-Z0-9]+ ----------------------one or more alphanumeric characters

[ \t\n]+ -------------------------------whitespace

[^ab] ---------------------------------anything except : a,b

[a^b] ---------------------------------one of : a, ^, b

[a|b] ----------------------------------one of : a, | , b

a|b ------------------------------------one of : a, b

^[a-z] --------------------------------line starting with a character from a-z

[a-z]$ --------------------------------line ending with a character from a-z

^[a-z]$ -----------------------------line containing only a character from a-z