Grep regular expressions

Position

^ Beginning of line.
$ End of line.
^$ Empty line.
\< Start of word.
\> End of word.

Character

- -
[A-Z­a-z] Any lower and upper case letter.
[0-9] Any number.
[0-9­A-Z­a-z] Any lower and upper case letter or digit.

POSIX

- -
[:alpha:] Any lower and upper case letter.
[:digit:] Any number.
[:alnum:] Any lower and upper case letter or digit.
[:space:] Any whites­pace.

Quantifiers

- -
{n} Previous item appears exactly n times.
{n,} Previous item appears n times or more.
{,m} Previous item appears n times maximum.
{n,m} Previous item appears between n and m times.

Wildcards

- -
. Any character.
? Optional and can only occur once.
* Optional and can occur more than once.
+ Required and can occur more than once.

Refer

  • Regex syntax (quickref.me)
  • Regex examples (quickref.me) Please refer to the full version of the regex cheat sheet for more complex requirements.
Comments