This tool is built on crates.io/crates/regex, the most widely used regular expression library in Rust. It features high performance, linear-time execution, full Unicode support, no backtracking, protection against catastrophic backtracking (ReDoS), a simple API, and thread safety.
The regular expressions entered in this page are actually compiled and executed using Rust’s regex engine, and you can observe the results of different methods (find, find_all, captures, split, test), which helps with development and debugging.
[dependencies]
regex = "1"
use regex::Regex;
fn main() {
let re = Regex::new(r"\d+").unwrap();
if let Some(m) = re.find("abc123xyz") {
println!("{}", m.as_str());
println!("{}", m.start());
println!("{}", m.end());
}
}Output:
123
3
6
| Flag | Description | Example |
|---|---|---|
i | Case-insensitive matching | (?i)abc |
m | Multiline mode, ^ and $ match each line | (?m)^abc$ |
s | Allows . to match newline characters | (?s)a.*b |
x | Ignore whitespace and allow comments | (?x)a \s+ b |
U | Swap greedy / non-greedy behavior | (?U)a.*b |
u | Enable Unicode (enabled by default) | (?u)\w+ |
| Expression | Description | Example |
|---|---|---|
. | Matches any character (default excludes newline) | a.c |
\d | Matches digits | \d+ |
\D | Matches non-digits | \D+ |
\w | Matches word characters (Unicode) | \w+ |
\W | Matches non-word characters | \W+ |
\s | Matches whitespace characters | \s+ |
\S | Matches non-whitespace characters | \S+ |
^ | Start of string | ^abc |
$ | End of string | abc$ |
* | 0 or more repetitions of the previous expression | a* |
+ | 1 or more repetitions of the previous expression | a+ |
? | 0 or 1 repetition of the previous expression | colou?r |
{n} | Exactly n repetitions | \d{4} |
{n,m} | Between n and m repetitions | \d{2,6} |
[abc] | Character set, matches any one character | [abc]+ |
[^abc] | Negated character set | [^0-9] |
(abc) | Capturing group | (\d+) |
(?:abc) | Non-capturing group | (?:abc)+ |
(?P<name>abc) | Named capturing group | (?P<id>\d+) |
a|b | Alternation (OR) | cat|dog |
\b | Word boundary | \bword\b |
\B | Non-word boundary | \Bing\B |
\A | Start of text | \Aabc |
\z | End of text | abc\z |
\p{Han} | Unicode character class | \p{Han}+ |