doc • pcre

PCRE Pattern Syntax

Here is a brief quick reference to the more common patterns you can use in PCRE regular expressions. The most commonly used is ".*", meaning any number of any character. This is equivalent to the wildcard "*" in the shell.

QUOTING - To prevent a character from being interpreted as a pattern meta-character, quote it.

CHARACTERS - How to specify characters, non-printable or programmatically.

CHARACTER TYPES - Match based on type of character.


CHARACTER CLASSES - Match a range or set of characters. For example, "[abc]" would match either a, b or c.

POSIX named sets for use in character classes:

QUANTIFIERS - Use this to limit regular expressions to match as much or as little as possible. For example, given the string "The quick brown fox slyly jumped over the lazy dog", the pattern "T.*e" would return "The quick brown fox slyly jumped over the", while the pattern "T.*?e" would simply return "The". Possessive matches are like greedy ones, except that it evaluates all the way to the end of the string, and if there's more to the pattern after it, that part will be unfulfilled and the match will fail. "T.*+e" would not match the above string at all.

ANCHORS and SIMPLE ASSERTIONS - Match based on the position within the string.

ALTERNATION - Match any of several possible expressions.

CAPTURING - Return submatches.

COMMENT - You shouldn't need this in Gambas but maybe you're writing regular expressions to be used in several different languages.

OPTION SETTING - You should use the constants found in the RegExp class as arguments to the Compile or Exec methods to make your code more readable, but if you're generating regular expressions at run time, these may be useful.

BACKREFERENCES - Refer to previous submatches in the current match.

For more detailed information about the library, see or The above quick reference was adapted from the "pcresyntax" man page.