Regular expressions manipulate text and data. Expressions are comprised of normal text literals and special character metacharacters that can be escaped to regular characters with escape characters. With programs like grep, regex should be put in single quote, ', but can be .

Metacharacters

Single Character

MetacharacterNameMatches
.DotAny one character
[…]Character ClassAny character listed in brackets
[^…]Negated Character ClassAny character not listed in brackets
\charEscape characterCharacter after slash is used literally

Position

MetacharacterNameMatches
^CaretStart of a line
$Dollar signEnd of a line
\<Backslash less-thanStart of a word
\>Backslash greater-thanEnd of a word

Quantifiers

MetacharacterNameMatches
?Question markOptional; qualifier
*AsteriskAny number including zero of preceding
+PlusOne or more of the preceding
{N}Match exactlyMatch exactly N times
{N,}Match at leastMatch at least N times
{min, max}Specified rangeMatch between min and max times

Other

MetacharacterNameMatches
|AlternationMatches either expression
-DashIndicates a range
(…)ParenthesesUsed to limit scope of alternation
\1, \2, …BackreferenceMatches text previously matched within parentheses
\bWord boundaryBatches characters that typically mark the end of a word
\BBackslashThis is an alternative to using ”\\” to match a backslash for readability
\wWord CharacterMatches any word character (letters, numbers, and underscore)
\WNon-word characterThis matches any character that isn’t used in words (not a letter, number, or underscore)
\`Start of bufferMatches start of buffer
\‘End of bufferMatches end of a buffer