Regular Expressions
List of meta characters:
. ---> Any one character
? ---> Zero or one
+ ---> One or more
* ---> zero or more
^ ---> at the beginning of the string
$ ---> at the end of the string
[abc] ---> any one of a b c
{m} ---> 'm' times
{m,n} ---> at least m times, at most n times
| ---> or
\ ---> escape sequence character
\s ---> a space
\d ---> a digit
\w ---> a word
\b ---> a word boundary
\d ---> a single digit number (0 to 9)
\d\d ---> a two digit number (0 to 99)
\d\d\d ---> a three digit number (000 to 999)
NOTE: ?, +, *, {} are used as Quantifiers (to represent quantity)
\d{3,5} ---> either 3 digit or 5 digit number
hell?o ---> helo | hello
hell+o ---> hello | helllo | helllllo | ...
hrll*o ---> helo | hello | helllo | helllllo | ...
he(ll)+o ---> hello | hellllo | hellllllo | ...
S = "hi hello how are hello"
hello ---> Yes
^hello ---> No
hello$ ---> Yes
\d+ ---> a number
[0123456789]+ ---> a number
[0-9]+ ---> a number
\d{3} ---> a 4 digit ODD number
\d+\s\w+ ---> a number then a space then a word
\d+\s[a-z]+ ---> a number then a space then lowercase word
\d+\s[A-K764]{5,10} ---> a number then a space then min 5 max 10 char uppercase word between A - K 764
\d{3}:\d{2}:\d{4} --->
(ABC)?\d{3}:\d{4}[XYZ]? --->
Comments
Post a Comment