Module regex

Regular expression matching.

Compile patterns once and match against multiple strings.

Examples

import std::regex;

fn main() {
    let re = regex.new("[0-9]+");
    if re.is_match("abc123") {
        let m = re.find("abc123");
        println(m);  // "123"
    }
    re.free();
}

Contents

Functions

Function new

pub fn new(pattern: string) -> Pattern

Compile a regular expression pattern.

Panics if the pattern syntax is invalid.

Examples

let email_re = regex.new("[a-z]+@[a-z]+\\.[a-z]+");

Types

Struct Pattern

A compiled regular expression pattern.

Created by regex.new(pattern). Must be freed with free() when no longer needed to avoid leaking memory.

Traits

Trait PatternMethods

Methods available on a compiled Pattern.

Methods

fn is_match(self: Pattern, input: string) -> bool fn find(self: Pattern, input: string) -> string fn replace(self: Pattern, input: string, replacement: string) -> string fn free(self: Pattern)