Crate re2

Source
Expand description

Rust interface to the re2 regular-expression library. RE2 supports Perl-style regular expressions (with extensions like \d, \w, \s, …).

§Regexp Syntax

This module uses the re2 library and hence supports its syntax for regular expressions, which is similar to Perl’s with some of the more complicated things thrown away. In particular, backreferences and generalized assertions are not available, nor is \Z.

See Syntax for the syntax supported by RE2, and a comparison with PCRE and PERL regexps.

For those not familiar with Perl’s regular expressions, here are some examples of the most commonly used extensions:

  • "hello (\\w+) world"\w matches a “word” character
  • "version (\\d+)"\d matches a digit
  • "hello\\s+world"\s matches any whitespace character
  • "\\b(\\w+)\\b"\b matches non-empty string at word boundary
  • "(?i)hello"(?i) turns on case-insensitive matching
  • "/\\*(.*?)\\*/".*? matches . minimum number of times possible

The double backslashes are needed when writing string literals. However, they should NOT be used when writing raw string literals:

  • r"(hello (\w+) world)"\w matches a “word” character
  • r"(version (\d+))"\d matches a digit
  • r"(hello\s+world)"\s matches any whitespace character
  • r"(\b(\w+)\b)"\b matches non-empty string at word boundary
  • r"((?i)hello)"(?i) turns on case-insensitive matching
  • r"(/\*(.*?)\*/)".*? matches . minimum number of times possible

When using UTF-8 encoding, case-insensitive matching will perform simple case folding, not full case folding.

Re-exports§

pub use error::RE2Error;
pub use options::Anchor;
pub use options::CannedOptions;
pub use options::Options;

Modules§

error
Error codes and additional data.
filtered
Routines for extracting fixed string “atoms” from a set of patterns and using those to pre-filter for later matching.
options
Configuration accepted by the pattern compiler.
set
Routines for matching against multiple separate patterns at once.
string
Wrappers for string data that interact with C++.

Structs§

NamedGroup
An FFI handle to a string-index pair representing a named parenthetical capture group.
RE2
High-level string search and replacement with a single pattern.