RegEx Tester
source : http://www.regular-expressions.info/javascriptexample.html
For Java RegEx Tester : http://www.regexplanet.com/advanced/java/index.html
Regex syntax
flags
g- global matchi- ignore casem- match over multiple lines
Escaping
\- special characters to literal and literal characters to special
Quantifiers
?- matches zero or one times*- matches zero or more times+- matches one or more times{n}- matches n times{n, m}- matches at least n times, but not more than m times
Anchors
^- matches at the start of the line$- matches at the end of the line\b- matches at the beginning or the end of a word
delimiter
(?:x)- matches x not remember the matchx(?=y)- matches x only if x is followed by yx(?!y)- matches x only if x is not followed by y
Character Escapes
\s- matches whitespace\S- matches anything but a whitespace\f- matches a form-feed\n- matches a linefeed\r- matches a carriage return\t- matches a horizontal tab\v- matches vertical tab\d- matches any digit\D- matches anything except digit\w- matches any alphanumeric character including the underscore. Equivalent to [A-Za-z0-9_]\W- matches any non-word character. Equivalent to [^A-Za-z0-9_]
Others
.- matches any character except a newline
Some predefined RegEx :
Positive Integers --- ^\d+$
Negative Integers --- ^-\d+$
Integer --- ^-{0,1}\d+$
Positive Number --- ^\d*\.{0,1}\d+$
Negative Number --- ^-\d*\.{0,1}\d+$
Positive Number or Negative Number - ^-{0,1}\d*\.{0,1}\d+$
Phone number --- ^\+?[\d\s]{3,}$
Phone with code --- ^\+?[\d\s]+\(?[\d\s]{10,}$
Year 1900-2099 --- ^(19|20)[\d]{2,2}$
Date (dd mm yyyy, d/m/yyyy, etc.) --- ^([1-9]|0[1-9]|[12][0-9]|3[01])\D([1-9]|0[1-9]|1[012])\D(19[0-9][0-9]|20[0-9][0-9])$
IP v4 --- ^(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]){3}$
Personal Name --- ^[\w\.\']{2,}([\s][\w\.\']{2,})+$
Username --- ^[\w\d\_\.]{4,}$
Password at least 6 symbols --- ^.{6,}$
Password or empty input --- ^.{6,}$|^$
email --- ^[\_]*([a-z0-9]+(\.|\_*)?)+@([a-z][a-z0-9\-]+(\.|\-*\.))+[a-z]{2,6}$
domain --- ^([a-z][a-z0-9\-]+(\.|\-*\.))+[a-z]{2,6}$
Match no input --- ^$
Match blank input --- ^[\s\t]*$
Match New line --- [\r\n]|$
No comments:
Post a Comment