rustWord boundary example in regex in Rust
Word boundary in regex is a zero-width assertion that matches the position between a word character (a-z, A-Z, 0-9, and _) and a non-word character. In Rust, it is represented by the \b character.
Example code
let re = Regex::new(r"\bword\b").unwrap();
let text = "This is a word";
println!("{}", re.is_match(text));
Output example
true
Code explanation
Regex::new(r"\bword\b"): creates a new Regex object with the pattern\bword\blet text = "This is a word": creates a string variable with the textThis is a wordre.is_match(text): checks if the Regex pattern matches the text
Helpful links
Related
- How to replace a capture group using Rust regex?
- How to use regex lookbehind in Rust?
- How to match whitespace with a regex in Rust?
- Regex example to match multiline string in Rust?
- How to replace all matches using Rust regex?
- How to match the end of a line in a Rust regex?
- How to match a URL with a regex in Rust?
- How to use Unicode in a regex in Rust?
- How to replace strings using Rust regex?
- How to parse a file with Rust regex?
More of Rust
- How to replace strings using Rust regex?
- How to match whitespace with a regex in Rust?
- Regex example to match multiline string in Rust?
- How to replace a capture group using Rust regex?
- How to match the end of a line in a Rust regex?
- How to use regex to match a double quote in Rust?
- How to print a Rust HashMap?
- How to convert a Rust HashMap to a JSON string?
- How to create a HashSet from a Range in Rust?
- How to convert the keys of a Rust HashMap to a vector?
See more codes...