Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ rust-version = "1.56"

[dependencies]
once_cell = "1.17"
regex = {version = "1.9", default_features = false, features = ["std"], optional = true}
regex = {version = "1.9", default_features = false, optional = true}
regex-lite = {version = "0.1", optional = true}

[dependencies.lazy-regex-proc_macros]
Expand Down
20 changes: 20 additions & 0 deletions examples/regexes/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,26 @@ fn example_builds() {

// Try to uncomment the following line to see the compilation error
// let r = regex!("(unclosed");

// build a bytes::Regex macro
let rb = bytes_regex!("b+");
assert!(rb.is_match(b"abcd"));
let rb = bytes_regex!("sa+b?$"i);
assert_eq!(rb.is_match(b"Saa"), true);

// build a bytes::Regex macro using the suffix syntax
let rb = regex!("b+"B);
assert!(rb.is_match(b"abcd"));

// 4 equivalent ways to build a case insensitive bytes::Regex
let case_insensitive_regex = bytes_regex!("^ab+$"i);
assert!(case_insensitive_regex.is_match(b"abB"));
let case_insensitive_regex = bytes_regex!("(?i)^ab+$");
assert!(case_insensitive_regex.is_match(b"abB"));
let case_insensitive_regex = regex!("^ab+$"iB);
assert!(case_insensitive_regex.is_match(b"abB"));
let case_insensitive_regex = regex!("(?i)^ab+$"B);
assert!(case_insensitive_regex.is_match(b"abB"));
}

fn example_is_match() {
Expand Down
29 changes: 24 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ With lazy-regex macros, regular expressions

The [regex!] macro returns references to normal instances of [regex::Regex] or [regex::bytes::Regex] so all the usual features are available.

Other macros are specialized for testing a match, replacing with concise closures, or capturing groups as substrings in some common situations:
But most often, you won't even use the `regex!` macro but the other macros which are specialized for testing a match, replacing, or capturing groups in some common situations:

* [regex_is_match!]
* [regex_find!]
Expand All @@ -19,6 +19,8 @@ Other macros are specialized for testing a match, replacing with concise closure

All of them support the `B` flag for the `regex::bytes::Regex` variant.

All macros exist with a `bytes_` prefix for building `bytes::Regex`, so you also have [bytes_regex!], [regex_is_match!], [regex_find!], [regex_captures!], [regex_replace!], and [regex_replace_all!].

Some structs of the regex crate are reexported to ease dependency managment.

# Build Regexes
Expand Down Expand Up @@ -61,17 +63,26 @@ assert_eq!(r.find("This is lazy_regex-2.2!").unwrap().as_str(), "lazy_regex-2.2"
let r = regex!("(unclosed");

```
Supported regex flags: `i`, `m`, `s`, `x`, `U`.
Supported regex flags: [`i`, `m`, `s`, `x`, `U`][regex::RegexBuilder], and you may also use `B` to build a bytes regex.

The following regexes are equivalent:
* `bytes_regex!("^ab+$"i)`
* `bytes_regex!("(?i)^ab+$")`
* `regex!("^ab+$"iB)`
* `regex!("(?i)^ab+$"B)`

They're all case insensitive instances of `regex::bytes::Regex`.

See [regex::RegexBuilder].

# Test a match

```rust
use lazy_regex::regex_is_match;
use lazy_regex::*;

let b = regex_is_match!("[ab]+", "car");
assert_eq!(b, true);
let b = bytes_regex_is_match!("[ab]+", b"car");
assert_eq!(b, true);
```

doc: [regex_is_match!]
Expand Down Expand Up @@ -168,12 +179,20 @@ doc: [lazy_regex!]

pub use {
lazy_regex_proc_macros::{
lazy_regex, regex,
lazy_regex,
regex,
regex_captures,
regex_find,
regex_is_match,
regex_replace,
regex_replace_all,
bytes_lazy_regex,
bytes_regex,
bytes_regex_captures,
bytes_regex_find,
bytes_regex_is_match,
bytes_regex_replace,
bytes_regex_replace_all,
},
once_cell::sync::Lazy,
};
Expand Down
Loading