// include the latest version of the regex crate in your Cargo.toml
extern crate regex;
use regex::Regex;
fn main() {
let regex = Regex::new(r"(?m)REGISTER sip:(?<your_field>(.|\n)+)User-Agent:").unwrap();
let string = "03:25:17.296: SIPTR: Received [0,UDP] 543 bytes from 10.xx.7x.1xx:8080 <<<<<
REGISTER sip:10.xx.7x.1xx SIP/2.0
Via: SIP/2.0/UDP 10.xx.7x.1xx;branch=hkhi8u09uj
From: \"Dummy\" ;tag=78979uh
CSeq: 68789 REGISTER
Call-ID: xxxxxx-7689-xxxx@10.xx.7x.1xx
Contact: ;methods=\"INVITE, ACK, BYE, CANCEL, OPTIONS, UPDATE, REFER\"
User-Agent: Polycom_r64786r9879r87
Accept-Language: en
Max-Forwards: 70
Expires: 60";
// result will be an iterator over tuples containing the start and end indices for each match in the string
let result = regex.captures_iter(string);
for mat in result {
println!("{:?}", mat);
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Rust, please visit: https://docs.rs/regex/latest/regex/