Use Perl 5 expressions to create search criteria
- Last Updated: June 26, 2019
- 1 minute read
- OpenEdge
- Version 13.0
- Documentation
The following table identifies some Perl 5 regular expressions you can use. Similarly, the Examples using the Perl 5 regular expressions table suggests specific examples based on this notation.
| Perl 5 expression | Description |
|---|---|
| . | Matches exactly one character, regardless of what the character is. |
| ? | The preceding item is optional and matched at most once (error if no preceding item). |
| * | The preceding item will be matched zero or more times (error if no preceding item). |
| + | The preceding item will be matched one or more times (error if no preceding item). |
| ^ | Match at beginning of a line. |
| $ | Match at end of a line. |
| {n} | The preceding item is matched exactly n times (error if no preceding item). |
| {n, } | The preceding item is matched n or more times (error if no preceding item). |
| {,m} | The preceding item is optional and is matched at most m times (error if no preceding item). |
| {n,m} | The preceding item is matched at least ntimes, but not more than m times (error if no preceding item). |
| [abc] | Matches the characters a OR b OR c. |
| [a-z] | Matches any character from a to z. |
| [^abc] | Matches any character EXCEPT a, b, or c. |
| \d | Matches exactly one digit. |
| \D | Matches any character EXCEPT a digit. |
| \w | Matches exactly one letter, number, or the underscore character(_). |
| \W | Matches any one character EXCEPT a letter, number, or the underscore character. |
| \s | Matches exactly one character of white space (for example, spaces, tabs, newlines, or any character that would not use ink if printed on a printer). |
| \S | Matches any character that is NOT a white space. |
| \ | Dereferences metacharacters (called "quoting"). |
| | | Separates two or more choices such as either|or behavior. |
The following table provides some examples based on the Perl 5 regular expressions identified in the above table.
| Example | Description |
|---|---|
| ^error | Matches the exact word error only when it appears at the beginning of a line. |
| \(9239\)$ | Matches the exact entry (9239) only when it appears at the end of a line. |
| da.*e | Matches the exact words date, daze, database, and dattape. This Perl 5 regular expression, .*, is similar to the wild card * on UNIX. |
| abc|abd|abe | Matches abc, abd, and abe. |
| b.d | Matches bad, bud, and bid, but not bald. |
| da.....e | Matches database and dattape, but not date and daze. |
| 3.14 | Matches 3.14, 3f14, and 3814. |
| 3\.14 | Matches 3.14, but not 3f14 and 3814. |
| ab?c | Matches ac and abc. |
| ab*c | Matches ac, abc, abbc, abbbc, and so forth. |
| ab+c | Matches abc, abbc, and so forth, but not ac. |
| d\.*z | Matches dz, d.z, d..z, d...z, and so forth. |
| d.\*z | Matches da*z, db*z, dc*z, and so forth. |
| 1\.\d\d | Matches any three-digit floating point number from 1.00 to 1.99******. |
| a\Dc | Matches abc, a&c, and aFc, but not a2c or a8c. |
| a\wc | Matches abc, aGc, and a_c, but not a%c. |
| a\Wc | Matches a%c, a?c, and a c, but not abc, aGc, or a_c. |
| a\sc | Matches any three-character string starting with a and ending with c whose second character is a space, tab, or newline. |
| a\Sc | Matches any three-character string starting with a and ending with c whose second character is not a space, tab, or newline. |
| ab{3,5}c | Matches abbbc, abbbbc, abbbbbc, only. |
| .{3,5} pentane | Matches cyclopentane, neopentane, and isopentane, but not n-pentane. |
| a[bc]d | Matches abd and acd, only. |
| a[a-z]c | Matches any three-character string starting with a and ending with c, and whose second character is any letter from a to z, inclusive. |