pub fn find_pattern(haystack: &[u8], needle: &Regex) -> Option<(usize, usize)>
Expand description
Find a regex pattern in a byte slice.
This is a utility function that uses regex to find patterns in byte data. It’s used internally by the streaming functions but can also be used directly for in-memory pattern matching.
§Arguments
haystack
- The byte slice to search inneedle
- The compiled regex pattern to search for
§Returns
Returns Some((start, length))
if the pattern is found, None
otherwise.
§Examples
use async_regex::find_pattern;
use regex::bytes::Regex;
let regex = Regex::new(r"\w+").unwrap();
let data = b"hello world";
if let Some((start, len)) = find_pattern(data, ®ex) {
println!("Found pattern at position {} with length {}", start, len);
}