// 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]*)(.|,)[\d](e|E)[\d]+").unwrap();
let string = "Valid floating points:
1
+1
-1
65
+65
-65
5.2
5,2
5.225
5,225
985.225
985,225
985.
,225
+5.2
+5,2
+5.225
+5,225
+985.225
+985,225
+985.
+,225
-5.2
-5,2
-5.225
-5,225
-985.225
-985,225
-985.
-,225
5.2E3
5.2e3
+5.2e3
-5.2e3
5,2E3
5,2e3
-5,2e3
+5,2e3
5.2e112
+5.2e112245
-5.2e99999
5,2e112
-5,2e112245
+5,2e99999
5.2e+3
+5.2e+3
-5.2e+3
5,2e-3
-5,2e-3
+5,2e-3
5.e3
5.e+3
+5.e+3
-5.e+3
5,e-3
-5,e-3
+5,e-3
,225e123
+,225e123
-,225e123
.225e123
+.225e123
-.225e123
Not floating points
,
,
,
.
.
.
.e
,e
.e2
,e2
,225e
+,225e
-,225e
.225e
+.225e
-.225e";
// 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/