Creating more readable regular expressions with Simple Regex Language

Clear-Sighted

Article from Issue 199/2017
Author(s):

Regular expressions are a powerful tool, but they can also be very hard to digest. The Simple Regex Language lets you write regular expressions in natural language.

Regular expressions are a fundamental feature of Linux – and many other modern operating systems. A regular expression is a search term with special placeholders representing several possible characters at the same time. The concept of a regular expression is an extension of the idea behind the "wildcard" character used in many GUI search tools, but the power and subtlety of regular expressions far exceeds what you can do with a simple wildcard.

For example, suppose you want to search the system.log file for errors, but you don't know whether the term Error will appear with initial cap or all lowercase (Error or error). You could use a regular expression as part of the Grep command:

grep -e '[eE]rror' system.log

[...]

Use Express-Checkout link below to read the full article (PDF).

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Regex Generators

    As regular expressions grow in complexity, regex generators can make the job easier by computing the patterns for you.

  • rename

    The rename command is a powerful means to simultaneously rename or even move multiple files following a given pattern.

  • Command Line – tre-agrep

    Tre-agrep has all of grep's functionality but can also do ambiguous or fuzzy searches without deep knowledge of regular expressions.

  • Command Line: Grep

    Once you understand the intricacies of grep, you can find just about anything.

  • Go Programming

    The Go programming language combines type safety with manageable syntax and an extensive library. We take you through a programming example.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News