Regex 101-01: What are Regular Expressions?

What is Regex?

Regular Expressions (REGEX, REGEXP) are used for pattern matching, text manipulation and parsing data. They are available in many modern programming languages such as Perl, PHP, Python, Ruby & Javascript as well as countless utilities such as grep and software programs. Regex comes in slightly different ‘flavours‘ based on the programming language or application. We will be learning PCRE version, this stands for Perl Compatible Regular Expressions, the perl programming language is credited for popularizing its usage. (PHP uses PCRE for example).

Regex Software:

These are referred to as regex visualizers, they aid in crafting regex by giving visual aids. Some great software/web apps to start learning are seen below:

Terminology:

This tutorial series will cover the regex terminology below.

An atom is any unit that can match.

Matches exactly as presented ‘literally’.

Tries to match an individual character within square brackets [abc]

So far we have only seen literal matches and individual character matches. Regex has the ability to multiply atoms.

Matches start ^ or end $ of string.

\b is a zero width assertion, meaning it doesn’t appear in resulting match but affects the outcome. the \b tries to match instances where a ‘word’ character transitions to a non word (for example white space ).

Tries to match left of | if fails tries the next alternative.

Like a quantifier but it matches a particular amount of times.

Character classes have some shortcut equivalents. These are called metacharacters.

Capture groups save to memory a segment within parentheses and assign a variable to it. Starting at 1 and incrementing to 9.

Positive and negative look arounds are zero width assertions. This means they affect the outcome of the match but are not included in the results. (Like word boundaries and anchors).

Modifiers change the behavior of the regex pattern. 2 methods to invoke them (inline) or at the end of the pattern (Varies on programming language/application).


πŸ‘ Get Blog Updates

πŸ“ Latest Posts

0Shares
0

One thought on “Regex 101-01: What are Regular Expressions?

Leave a Reply