Duncan Wither

Home Notes Github LinkedIn

Terminal Tut 4 - Regex

Written: 05-Mar-2022

This is just a short article explaining regex to keep the cheat sheet de-cluttered.

What is regex?

It allows for easy text parsing. Ask your local friendly search engine for more info

How does it work?

The gist is it looks through an input string (or file) and identifies matches with the search expression The search expression can be as simple as a word, or more complex. The cheat-sheet explains the basics, and enables you to build up more complex search patterns.

This basic (made up) example would find the word “color” (as it’s a common misspelling1) in a text file about paintings:

grep "color" "painting.txt"

grep is short for “get regular expression”2.

Why?

Matching patterns allows you to then modify the text (using a command like sed) or to single out specific points of interest (like file names using find . -regex).

To learn it, try creating search patterns using the cheat sheet, and testing them in the terminal or online.

Done

That’s all the little things I’ve got. Look at the cheat-sheets if you’re still curious:

Previous…

Terminal Tut 3 - Scrpting


  1. It is spelled colour of course.↩︎

  2. I’ve no citation, but surely it is.↩︎