// 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)(?<!(i|e))[.,!?][a-zA-Z0-9]").unwrap();
let string = "The problem:
Match lack of space following a fullstop/period. BUT! don't match on \"i.e.\" and \"e.g.\"
The current attempt above is not robust, only matches the \"i\" of \"i.e.\" and \"e\" of \"e.g.\" and, worse, allows all other sentences ending with \"i\" or \"e\".
Example source:
PASS: This is a test (i.e. something).Match M with no space. Don't match i.e.
PASS: This is a test (e.g. Something).Match M with no space. Don't match e.g.
PASS: This is a test (q.v. something).Match M with no space. DO match .v (not required)
PASS: This is a test.match the m.
PASS: Is this a test?Match the M.
PASS: This is a test!Match the M.
These all fail:
(?<!(i\\.e|e\\.g))[.,!?][a-zA-Z0-9]
(?<!(i\\.e\\.|e\\.g\\.))[.,!?][a-zA-Z0-9]
(?<!(i\\.e|e\\.g))(\\.|\\!|\\?)\\s+“?[a-z]
Current working copy:
(?<!(i|e))[.,!?][a-zA-Z0-9]";
// 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/