[][src]Crate fancy_regex_fork_pb

An implementation of regexes, supporting a relatively rich set of features, including backreferences and look-around.

It builds on top of the excellent regex crate. If you are not familiar with it, make sure you read its documentation and maybe you don't even need fancy-regex.

If your regex or parts of it does not use any special features, the matching is delegated to the regex crate. That means it has linear runtime. But if you use "fancy" features such as backreferences or look-around, an engine with backtracking needs to be used. In that case, depending on the regex and the input you can run into what is called "catastrophic backtracking".

Usage

The API should feel very similar to the regex crate, and involves compiling a regex and then using it to find matches in text.

An example with backreferences to check if a text consists of two identical words:

use fancy_regex::Regex;

let re = Regex::new(r"^(\w+) (\1)$").unwrap();
let result = re.is_match("foo foo");

assert!(result.is_ok());
let matched = result.unwrap();
assert!(matched);

Note that like in the regex crate, the regex needs anchors like ^ and $ to match against the entire input text.

Example: Find matches

use fancy_regex::Regex;

let re = Regex::new(r"\d+").unwrap();
let result = re.find("foo 123");

assert!(result.is_ok(), "execution was successful");
let match_option = result.unwrap();

assert!(match_option.is_some(), "found a match");
let m = match_option.unwrap();

assert_eq!(m.start(), 4);
assert_eq!(m.end(), 7);
assert_eq!(m.as_str(), "123");

Modules

analyze

Analysis of regex expressions.

compile

Compilation of regexes to VM.

parse

A regex parser yielding an AST.

vm

Backtracking VM for implementing fancy regexes.

Structs

Match

A single match of a regex in an input text

RegexBuilder

Regular expression builder.

SubCaptureMatches

Enums

Captures
Error
Expr
LookAround
Regex

Type Definitions

Result