Regular Expressions

Useful site for writing and testing regex

image.png

Image Source: https://twitter.com/manekinekko/status/1335330878403260419

codePurpose
\drepresent any digit 0-9
[0-9] or [abc]matches a range or any specfic item in the brackets could find a,b, or c but will find all of them
\Dmatch any NON-digit characters
[^0-9] or [^\d]says match all BUT these in which case this is digits
\wwill match words, \D will match white space, punctuation, hyphens, etc. while \w does not. \w matches only letters and numbers, equivalently: [a-zA-Z0-9]
\Wto match a non word character. matches opposite of alphanumeric and is equivalent to [^_a-zA-Z0-9]
\smatch a space character
\nNew line
\ta tab
\rcarriage return
.match any single character
\bboundry, so for a word \bA.{5}T\b the boundries encompass words that start with 'A', end with 'T' and have 5 characters in the middle like ANCYENT or ANCIENT also akin to \b\w{7}\b
^beginning of a line anchor
$end of a line anchor
the pipe is an 'or' statement in brackets is saying 't' OR 'T' in a regex search
[0-3[4-5]]Union of 2 character sets, this would return 04, 05, 14, 15, 24, 25, 34, 35, this can also work with negation to use a set of 'NOT THESE' characters

QuantifierDescription
{8}quantifyer, same as linux CLI .{8} would match any 8 characters, this one matches the patter a specific number of times, 8 times.
{8,}the comma means it will match or more occurances of the pattern
{2,4}will match the pattern anytime it ocurs 2-4 times any of those options are captured

Backlinks