// 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"\$[A-Za-z]{0,4}[0-9]{0,1}").unwrap();
let string = "# This is test program 1. This program does nothing useful.
add $s0, $0, $zero
addi $t0, $t0, 100#test comment
addi $a0, $a0,100
test: add $s0, $s0, $a0 # this is a comment
addi $a0, $a0, -1
bne $a0, $0, test # this is another comment
addi $a0, $a0, 100
test1:
#test comment
lw $a0, 8($a1)
sw $a0,4($a1)
j test1
jr $ra
jal test1
slt$t0,$a0,$a1
beq$t0,$t1,test
sub $t3, $t1, $t1
sll $a0, $a1, 2
";
// 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/