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\b
let text = "This is a word"
: creates a string variable with the textThis is a word
re.is_match(text)
: checks if the Regex pattern matches the text
Helpful links
Related
- How to match whitespace with a regex in Rust?
- How to replace strings using Rust regex?
- How to use Unicode in a regex in Rust?
- How to match the end of a line in a Rust regex?
- How to split a string with Rust regex?
- How to use 'or' in Rust regex?
- How to get a capture group using Rust regex?
- How to match all using regex in Rust?
- How to replace a capture group using Rust regex?
- How to find the first match in a Rust regex?
More of Rust
- How to create a HashMap of HashMaps in Rust?
- How to swap elements in a Rust slice?
- How to extend struct from another struct in Rust
- How to get a capture group using Rust regex?
- How to replace a capture group using Rust regex?
- Hashshet example in Rust
- How to get an entry from a HashSet in Rust?
- How to convert a Rust slice of u8 to a string?
- How to find the first match in a Rust regex?
- How to calculate the sum of a Rust slice?
See more codes...