Your RegEx Cheat Sheet
Regular expressions, or Regexes, are a special kind of text string used to describe patterns in text. They’re extremely powerful tools for working with and modifying large amounts of text quickly, which is why they’re often used by developers and other professionals who need to deal with a lot of data. But they can also be intimidating! This cheat sheet will help you get started writing regex expressions and show you some helpful tricks along the way.
For example, say you wanted to find all the phrases in your text that matched a certain pattern of words (for example, “I love pizza” or “Bella went to school today”). If you want to match the phrase “I love pizza,” you would search for this regex expression: I\s+love\s+pizza. The \s part stands for any whitespace character like space and tab, and the + indicates that there can be one or more of those characters.
Now, if you wanted to find all the phrases that matched “Bella went to school today,” you would search for this regex expression: Bella\s+went\s+to\s+school\s+today. The \s part stands for any whitespace character, and + indicates that there can be one or more of those characters.
Now that we have some background information about Regexes, let’s take a look at what kinds of tasks are best suited for them.
For example, a regular expression might be used to find the position of words in a sentence or find text that is formatted with certain HTML tags. In addition, regexes can also search large amounts of data such as log files and computer folders for specific strings (e.g., names of photos). Regular expressions are also excellent at finding patterns and making replacements on large groups of data.
We’ve seen how a few examples work now; let’s look at some more!
Most modern programming languages have built-in support for regular expressions. If you need to use them often, it may be worth looking into learning about one (or all) of these languages, for example:
Writing regular expressions can be a little tricky, so you may find it helpful to check out some of the resources available on Regular Expression Tutorials and References. You might also want to read up on what makes for a good regex when using Python’s re module.
Recommended by LinkedIn
Now that you have an understanding of Regexes, see the full reference guide, including symbols, ranges, grouping, assertions, and some sample patterns:
Scale QA with Generative AI tools.
A testRigor specialist will walk you through our platform with a custom demo.
👍 (?X) -> (?<name>X) or (?P<name>X) [:word:] -> [[:word:]]