Regular Expression Syntax Used in Patterns
A Pattern represents a regular expression (regex), a sequence of characters typically used to perform a pattern match.
This topic summarizes the use of the most common regex characters that can be used when you are adding or editing a Project Pattern.
Pattern Syntax
Any character matches itself in a pattern unless the character is one of the designated special characters. To override the designated meaning of a special character and treat it as the literal character, you must precede the character with the escape character \. The following are regex special characters:
. [ ] { } ( ) \ * + ? | ^ $ '
Any single character or marked subexpression can be repeated with the *, +, ?, and {} operators.
Digital Reef supports the java.util.regex package.
Summary of Selected Special Characters
Character | Behavior |
---|---|
.
(period or dot) |
Character match – When used outside of a character set matches any single character. When used inside a bracket set (a Pattern starting with [ and ending with ] that defines a set of characters), matches any single character that is a member of that set. |
\
(backslash) |
Escapes a special character – Put an escape character before any character that you want to include as a literal in the Pattern. For example, to match c:\ , type the Pattern as c:\\ . To match [note] , type \[note\] . |
[ ]
(brackets) |
Character Set – Defines a character set. A bracketed-Pattern starts with [ and ends with ]. Defines a set of characters and matches any single character that is a member of that set. For example, to match a character using a character range: [a-z]. |
{ }
(braces) |
Grouping – A single character or marked subexpression can be repeated with a bounded repeat. Examples:
a{n} matches 'a' repeated exactly n times.
a{n,} matches 'a' repeated n or more times.
a{n,m} matches 'a' repeated between n and m times inclusive. |
( )
(parenthesis) |
Grouping – Used to group alternatives (for example, ab(d|ef) will match either of abd or abef). |
*
(asterisk) |
Quantifier – Match the preceding single character or marked subexpression zero or more times. For example the expression a*b will match any of the following:
b ab aaaaaaaab |
+
(plus) |
Quantifier – Match the preceding single character or marked subexpression one or more times. For example the expression a+b matches any of ab and aaaaaaaab but not b . |
?
(question mark) |
Quantifier – Match the preceding single character or marked subexpression zero times or one time. For example, the expression ca?b will match
cb or cab but not
caab. |
|
(pipe) |
OR operator – Matches either of its arguments. Examples: abc|def matches either abc or def . |
^
(caret) |
Position – Matches the start of a line (start of a term). |
$
(dollar sign) |
Position – Matches the end of a line (end of a term). |
\b | Word Boundary – Indicates a word boundary. |
\d | Digit – Represents any digit, that is, any of 0 1 2 3 4 5 6 7 8 9. |
(?i) | Pattern Modifier - Case insensitive. |