Interested in improving this site? Please check the To Do page.

Back to Regular Expression (re) Verbs

re.compile

Compiles pattern into the internal byte-code representation for a regular expression, taking the specified options into account.

Syntax

re.compile (pattern, flCaseSensitive, flDotMatchesAll, flMultiLine, flAutoCapture, 
            flGreedyQuantifiers, flMatchEmptyString, flExtendedMode)

Params

  • pattern is a string containing the regular expression to be compiled.
  • flCaseSensitive is an optional boolean determining whether the pattern should be case-sensitive. Defaults to false.
  • flDotMatchesAll is an optional boolean determining whether the dot meta-character matches all characters including newlines. Defaults to true.
  • flMultiLine is an optional boolean determining whether the target string should be treated as multiple lines of text. Defaults to true.
  • flAutoCapture is an optional boolean determining whether all parentheses should automatically capture any substrings that they might match. Defaults to true.
  • flGreedyQuantifiers is an optional boolean determining whether quantifiers should be greedy. Defaults to true.
  • flMatchEmptyString is an optional boolean determining whether the empty string should be considered a valid match for the pattern. Defaults to true.
  • flExtendedMode is an optional boolean determining whether whitespace should be ignored and comments should be enabled in patterns. Defaults to false.

Returns

A binary value of type 'PCRE' that contains the internal byte-code representation of the pattern.

Examples

re.compile ("a?b?")

compiled pattern that matches ””, “a”, “b”, and “ab”

re.compile ("a?b?", flCaseSensitive:false, flMatchEmptyString:false)

compiled pattern that matches “a”, “A”, “b”, “B”, “ab”, “Ab”, “aB”, and “AB”, but not ””

Errors

An error will be generated if the pattern is not syntactically valid. Usually, the error message will include the position in the pattern string where the offending character was encountered.

Notes

  • If the flDotMatchesAll param is set to false, any dot meta-characters in the pattern will match any character except for newlines.
  • If the flMultiLine param is set to false, the ^ and $ meta-characters will only match at the beginning and end of the target string, respectively, but not right after or right before or newline character.
  • If the flAutoCapture param is set to false, only named parentheses will capture the substrings that they matched.
  • If the flGreedyQuantifiers param is set to false, quantifiers will not be greedy by default, but greediness can be evoked for a quantifier by following it with a ”?”.
  • If the flMatchEmptyString param is set to false, an empty string will no longer be recognized as a valid match for a pattern like “a?b?” that could theoretically have matched the empty string.
  • If the flExtendedMode param is set to true, whitespace characters in the pattern are totally ignored except when escaped or inside a character class. In addition, characters between an unescaped # outside a character class and the next newline character, inclusive, are also ignored. This option makes it possible to include comments inside complicated patterns.
  • Several other re verbs require the return value of a call to re.compile as their first parameter. All of them treat this parameter as a read-only value. Therefore, it is save to share the same compiled pattern between several calls to other re verbs and indeed between several threads making calls to other re verbs.
  • While it is possible to assign the return value of re.compile to an arbitrary database address and use it in calls to other re verbs later, it should not be assumed that the compiled pattern will be accepted as valid by versions of Frontier running on a different platform or having a different version number.
  • The kernel implementation of the re verbs is based on the Perl Compatible Regular Expressions (PCRE) library. This is the same library used by Python, Apache, and PHP. Mandatory excerpt from the PCRE license:
  • Regular expression support is provided by the PCRE library package, which is open source software, written by Philip Hazel, and copyright by the University of Cambridge, England.
  • The source code for the PCRE library is available for download from ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/

See Also


Personal Tools