Regular Expressions

A regular expression, or 'regex' for short, is a string where certain characters (or groups of characters) have special meaning. These special characters are called 'metacharacters', as follows.

* Matches zero or more occurrences of the element preceding it
+ Matches one or more occurrences of the element preceding it
? Matches zero or one occurrences of the element preceding it
. Matches any single character, except a newline
[xyz] Matches any one of the enclosed characters)
[^xyz] Matches any character not given in xyz
[x-y] Matches any character in range x to y e.g. [a-z] matches any lowercase character, or [0-9] matches any digit, etc.
^ Anchors the match to the beginning of the string the regex is being applied to
$ Anchors the match to the end of the string the regex is being applied to
| Separates alternatives
{N,M} The preceding element must occur at least N times, but not more than M times
{N} The preceding element must occur exactly N times
{N,} The preceding element must occur at least N times
\x Treat x as a literal character, even if it would normally be a metacharacter

Here are some examples:

Regex Meaning Matches Does not Match
^Fred Matches strings that start with 'Fred' Fred
Freda
Frederick
Mr Fred Bloggs
^Fred.*s$ Matches strings that start with 'Fred' and end with 's', with any number of characters between (including 0). Fred Jones
Freds
Fred Smith
Mr Fred Jones
^Fred.+s Matches strings that start with 'Fred', followed by one or more characters (it doesnt matter what they are), followed by an 's'. The '.+' construct means 1 or more (+) of any character (.). Because there is no trailing $, the 'n' does not have to be at the end of the search string. Fred Jones Fred Smith
Mr Fred Jones
Freds
Fr?d? Matches strings that contain, anywhere, the 2 characters 'Fr', followed by any single character, followed by a 'd', followed by any single character, followed by anything else (including nothing). Frodo
John and Freda Smith
red
^[abc][0-9]+$ Matches strings that consist of the letter 'a', 'b' or 'c', followed by 1 or more digits. a56
b7
ab
a
ab5
5

Pedserve supports regex searching against any text field in the database. However, with very large databases this can be slow, because it forces MySQL to compare against the field for every record in the database; regex comparisons cannot use indexes to speed the search.

USEFUL LINKS:
 EULA
 Pedserve Editions
 Sample City
 Consultancy
 Data Preparation
 Installation
 Regular Expressions
 Similarity Searching
 Configuration File
 Setup Script
 Stylesheet
 Database Design
 Hooks
 Date/Time
 User Defined Fields
 User Defined Records
 Display Fields Definitions
 Ordering Fields Definitions
 Highlighting
 Page Layout
 Field Definitions
 Field Formatting
 Shortcut Query Buttons
 Plates
 Command Buttons
 Connecting to the Database
 Warning Footer Message