Introducing regular expressions
You might have heard the term regular expression, or regex, before. For many people, a regular expression is something that seems very complicated, and is often plucked somewhere from the internet or a textbook, without fully grasping what it does.
While that is fine for completing a set task, understanding regular expressions better than the average systems administrator really allows you to differentiate yourself, both in creating scripts and working on the Terminal.
A nicely tailored regular expression can really help you keep your scripts short, simple, and robust to changes in the future.
What is a regular expression?
In essence, a regular expression is a piece of text that functions as a search pattern for other text. Regular expressions make it possible to easily say, for example, that I want to select all lines that contain a word that is five characters in length, or look for all files that end in .log
.
An example might help with your understanding....