Regex fundamentals (03/23/2021)

Languages > Regex

To test regular expressions quickly: Regex101

abc123= //Exactly 'abc123='.
\d //Any digit.
\D //Any non-digit character.
. //Any single character.
\. //A '.'.
[abc] //'a', 'b' or 'c'.
[^abc] //Not 'a', nor 'b' nor 'c'.
[a-z] //Any character between 'a' and 'z'.
[0-9] //Same than '\d'.
\w //Any alphanumeric character. Equivalent to '[A-Za-z0-9_]'.
\W //Any non-alphanumeric character.
a{3} //'a' repeated 3 times.
a{3,6} //'a' repeated from 3 to 6 times.
a* //'a' repeated from 0 to many times.
a+ //'a' repeated from 1 to many times.
a? //An optional 'a'.
\s //A whitespace character between ' ', '\t', '\n' and '\r'.
\S //Any non-whitespace character.
^abc //'abc' at the start of the line.
abc$ //'abc' at the end of the line.
a(bc) //'bc' is in a capture group.
(a(bc)) //'abc' is in a group and 'bc' in a sub-group.
a(bc)* //Groups allow to apply repetition to multiple characters.
a(b|c) //Will match 'ab' or 'ac'.

Something to say ?

Leave a Reply

Your email address will not be published.