a-z matches an lower case letters from a to z
0-5 matches any number from 0 to 5
[a] matches the letter a
[abc] matches a single letter which can be a, b or c
[a-z] matches any single lower case letter of the alphabet.
See examples below.
[a]{2} matches two consecutive lower case letter a: aa
[a]{1,3} matches at least one and up to three lower case letter a, aa, aaa
a+ will match consecutive a's a, aa, aaa, and so on
Pattern may or may not be present but can only be matched one time.
[a-z]? matches empty string or any single lower case letter.
Wildcard for pattern that may or may not be present.
[a-z]* matches empty string or string of lower case letters.
a. Matches a two character string starting with a and ending with anything except \n
a|b means either a or b can be matched.
red|white|orange matches exactly one of the colors.
[^0-9] character can not contain a number
[^aA] character can not be lower case a or upper case A
\., \\, \(, \?, \$, \^
^a First character must be lower case letter a
^[0-9] First character must be a number.
a$ Last character must be lower case letter a
order | name | representation |
---|---|---|
1 | parentheses | ( ) |
2 | multipliers | ? + * {m,n} {m, n}? |
3 | sequence & anchors | abc ^ $ |
4 | alternation | | |
abbreviation | equal to | meaning |
---|---|---|
\d | [0-9] | any single digit |
\D | [^0-9] | any single character that's not a digit |
\w | [a-zA-Z0-9_] | any word character |
\W | [^a-zA-Z0-9_] | any non-word character |
\s | [ \r\t\n\f] | any space character |
\S | [^ \r\t\n\f] | any non-space character |
\n | [\n] | new line |
https://regexr.com/ or https://regex101.com/ work like charm ❤️