Declarative Objectivity (DO) Language : Expressions : Regular Expressions
Regular Expressions
Some String Operators test whether a string matches a pattern that is specified as a regular expression. DO implements its regular expressions based on the PCRE (Perl Compatible Regular Expression) library. The regular-expression metacharacters in the following table are a subset of the most commonly used ones.
 
Metacharacter
Description
.
Matches any single character. Loses its special meaning when used within [].
\
Used as a prefix operator to override any special meaning of the following character. Loses its special meaning when used within [].
 
Note: You must enter \\ if you want to indicate a single \ character.
[]
Used to bracket a sequence of characters or character ranges; matches any single character in the sequence or in one of the specified ranges.

If the first character in the sequence is ^, this pattern matches any character except the characters in the sequence and the specified ranges.

Note: Within [], you can use [ to match the character [, but you must use \] to match the character ].
-
When used within [], indicates a range of consecutive ASCII characters. For example, [0-5] is equivalent to [012345]. Loses its special meaning if it is the first or last character within [], or the first character after an initial ^.

No special meaning when used outside [].
*
Used as a postfix operator to cause the preceding pattern to be matched zero or more times. Loses its special meaning when used within [].
+
Used as a postfix operator to cause the preceding pattern to be matched one or more times. Loses its special meaning when used within [].
^
When used as the first character within [], causes the bracketed pattern to match any character not specified within [].

When used as the first character of a regular expression, matches the beginning of the string.

No special meaning in other locations in a regular expression.
$
When used as the last character of a regular expression, matches the end of the string.

No special meaning in other locations in a regular expression.
()
Used to group patterns into a single pattern (often used with the | operator).
|
OR operator in regular expressions; when used between two patterns, matches either one of the patterns.
?
? Matches the preceding element zero or one time. For example, ba? matches 'b' or 'ba'. Loses its special meaning when used within [].
Quick Look 
Find customers whose last names begin with 'Gr', such as 'Greene':
FROM Customers WHERE lastName =~ '^Gr' RETURN *;
Find customers whose last names end with 'son', such as 'Jackson':
FROM Customers WHERE lastName =~ 'son$' RETURN *;
Find customers whose last names contain 'son', such as 'Tilson Thomas' and 'Jackson':
FROM Customers WHERE lastName =~ 'son' RETURN *;
Find customers whose last names start with 'J', end with 'son', and have any number of characters in between, such as 'Jackson' and 'Jefferson':
FROM Customers WHERE lastName =~ '^J.*son$' RETURN *;
Discussion 
All characters not listed in the table are literals that match themselves. For example, the comparison character A in a regular expression matches the character A in a string; in a case-insensitive comparison, it also matches the character a.
Escape Sequences Within a Regular Expression
You can use escape sequences to represent characters that would otherwise be interpreted as regular-expression metacharacters:
Escape Sequence
Represented Character
\$
$
\(
(
\)
)
\.
.
\|
|
\[
[
\]
]
\*
*
\?
?
\-
-
\+
+
\^
^
For example, the following regular expression matches strings that contain any number of characters between parentheses:
'\(.*\)'