Posted by Rui Ying on Wednesday, May 12, 2021

Basic syntax

Character Description
^ start
$ end
. any one character
* >1 character
[] include
[^] not include (e.g. [^A-C] is any one except for ABC)
\w word = [A-Za-z0-9]
\W inverse of \w

A useful command

grep -rnw '/path/to/somewhere/' -e 'pattern'

  • -r recursive
  • -n line number
  • -w word regexp


If you use Emacs, you can forget the command and use projectile. This is a project managing package which provides strong search ability with ag/rg (you can still choose grep though).


In Linux, fuzzy finding fzf is another interesting program.