Regexp Builder

Emacs has an interactive regex mode that shows matches as you type.

To go into the mode, M-x regexp-builder.  Type C-c C-q to exit the mode.

Watch out for escape characters.  Emacs requires you to escape \, so type \b for \b

Copy the following text into emacs and then M-x regexp-builder

Lots of Grey things
50 shades of Grey
Earl Grey Tea
Lady Grey
Graybeard the pirate
Greyhound buses
"You're looking grey," he said.
"That's the greyest greyhound I ever saw," said Earl Grey.
Grey1: Dark Gray
Grey35: Mid grey
Grey44: Battleship grey
Grey100: The colour of TV tuned to a dead channel

In regexp-builder, type…

Grey to find all the Greys
Gray to find all the Grays
Gr[ae]y to find all the Greys and Grays
\\bGray\\b to find Gray on its on and not part of another word
^Gray to find lines beginning with Gray
grey$ to find lines ending in grey
grey\\(hound\\)? to find all appearances of grey and greyhound
grey[0-9] to find all the shades of grey ending with a digit
grey[0-9]\\{2\\} to find all the shades of grey with exactly two digits

Follow the link for some Regexp Exercises to try out

Read more about Regexps at the Emacs Wiki

Leave a Reply

Your email address will not be published. Required fields are marked *