Recent Forum Topics ![]() | ![]() | ![]() |
Regular expressions are a very powerful way of filtering strings.
The "normal" way of describing these are provided below. I have added examples to make it easier to understand:
A regular expression is one or more branches separated by `|´, matching anything that matches any of the branches.
Example 1:
foo|bar
This matches anything that contains the strings `foo´ or `bar´ such as: afoot, barred, barefoot.
A branch is zero or more constraints or quantified atoms, concatenated. It matches a match for the first, followed by a match for the second, etc; an empty branch matches the empty string.
A quantified atom is an atom possibly followed by a single quatifier. Without a quantifier, it matches a match for the atom. The quantifiers, and what a so-quantified atom matches, are:
An atom is one of:
A constraint matches an empty string when specific conditions are met. A constraint may not be followed by a quantifier. The simple constraints are as follows.
A regular expression may not end with `\´.
Example 2:
^foo
Matches any string that begins with the string foo: foot
Example 3:
fo+
Matches any string that contains an f followed by any number of `o´s: surface, afoot
Example 4:
[bar]{2,}$
Matches any string which ends with the last two characters being b, a or r: bar, dab, car, abracadabra