// 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)(?<!\d)(?<!_)(?<![a-zA-z])string(?!\d)(?!_)(?![a-zA-Z])").unwrap();
let string = "module mpi_hello_world
use mpi
implicit none
contains
subroutine hello_world(size, & ! testtest
& r_ank, &!
& myhostname &
& )
! this is a comment
! this also
integer, intent(in) :: size, rank23, rank_er,ranking, myrank, my2r_ank
character(len = *), intent(out) :: myhostname
integer :: stat
myhostname = \"(no host name)\"
#ifdef __INTEL_COMPILER
call get_environment_variable(\"COMPUTERNAME\", myhostname)
#else
stat = hostnm(myhostname)
#endif
write(*, *) \"Hello world FORTRAN rank:\", rank, \" size:\", size, &
& \"hostname:\", trim(myhostname)
end subroutine hello_world
end module mpi_hello_world
";
// 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/