Basic regular expressions

Ops Center Protector User Guide

Version
7.9.x
Audience
anonymous
Part Number
MK-99PRT002-10
ft:lastEdition
2024-12-11

Regular expressions (regex) are a powerful method of pattern matching in character strings. This topic describes a few basic regex terms. For a full explanation of regular expressions, please refer to one of the many books or online resources available.

Table. Commonly used regex matching terms
Type of Match Regex Example Action Explanation
Contains the sub-string (case sensitive) this Matches any string containing the sub-string this, respecting the case

e.g.:

Grab this thistle

A sub-string on its own will be matched anywhere within the search string.
Contains the sub-string (case insensitive) (?i)this Matches any string containing the sub-string this, without regard to case

e.g.:

Grab ThiS thIstle

The (?i) mode modifier turns off case sensitive matching
Starts with the sub-string ^this Matches any string starting with this

e.g.:

this is a tree

The ^ anchor means the sub-string must appear at the start of the string being searched
Ends with the sub-string that$ Matches any string ending with that

e.g.:

don't touch that

The $ anchor means the sub-string must appear at the end of the string being searched
Starts with any of the sub-strings ^(this|that|other) Matches any string starting with this or that or other

e.g.:

this time it matters

and:

that's life

and:

other types available

The | alternation operator indicates any sub-string in brackets will be matched
Contains any of the sub-strings (this|that) Matches any string containing this or that

e.g.:

you can't touch this

and:

please don't do that

The | alternation operator indicates either sub-string in brackets will be matched
Starts with sub-string 1 and ends with sub-string 2 ^this.*that$ Matches any string staring with this and ending with that

e.g.:

this is the answer to that

The . metacharacter matches any character, then the * quantifier indicates that zero or more of them will be matched