Monday, 1 February 2016

Regular Expressions

.   - Matches each and every character. 

bananas? - The last letter of the word is optional.


foo(bar)? - The enclosed string is optional.


1234?5678 - The digit 4 is optional.


[7-9] - Matches against numbers from 7-9.


[a-zA-Z0-9] - Matches against all alphanumeric characters/numbers.

fo+ - Letter 'O' can be repeated as many as number of times.


test(ing|er|ed)? - The word test can ends with ing , er or ed.


b(a|e|i)d - The middle letter of the word can be a,e or I.


[a-zA-Z1-9_]+@[a-zA-Z1-9]+\.(org|com|net) - Expression to validate Email address.

[a-z]{2} - No of times the characters can be repeated.

[a-z]{1,2} - No of times the characters can be repeated.

^foo$ - Starts with 'f' ends with 'o'


^\s* -  means any line beginning with whitespace.

(?:https?:\/\/)?(?:[a-zA-Z0-9])+\.(?:com|org|net) - Expression to evaluate web url.


<a href=["']([a-zA-Z1-9://\.]+)["']>(.+)<\/a> - Expression to evaluate hyper link



Following link is the excellent link where you can check the regular expressions. Also validate your expressions in very short time.

http://www.regexr.com/

No comments:

Post a Comment