// 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)[0-9]{3}[M]").unwrap();
let string = "[root@barpbli24149399 log]# ls -alhr | grep -E [\\d\\d\\dM]
-rw------- 1 root root 2.1K Nov 12 20:39 vmware-vmtoolsd-root.log
-rw------- 1 root root 719 Mar 11 2021 vmware-network.log
-rw------- 1 root root 719 Mar 11 2021 vmware-network.2.log
-rw------- 1 root root 741 Mar 11 2021 vmware-network.1.log
drwxr-xr-x. 2 root root 4.0K Dec 14 2020 tuned
-rw-r----- 1 root root 2.2K Mar 11 2021 tsy-install-hpsa.log
-rw-r--r-- 1 root root 184 Nov 12 20:39 TSM_CAD_-_BARPBLI24149399_FS.dsminfo
drwxrwxrwx 2 root root 4.0K Nov 28 06:51 tsm
-rw-------. 1 root root 16M Nov 28 09:10 tallylog
-rw------- 1 root root 139 Mar 16 2021 sudolog
drwxr-x---. 2 sssd sssd 4.0K Nov 13 03:08 sssd
-rw------- 1 root root 220 Mar 11 2021 serverprofile.log
-rw-r----- 1 root root 157K May 29 2022 seclog.log-20220529
-rw-r----- 1 root root 158K May 22 2022 seclog.log-20220522
-rw-r----- 1 root root 161K May 15 2022 seclog.log-20220515
-rw-r----- 1 root root 158K May 8 2022 seclog.log-20220508
-rw-r----- 1 root root 157K May 1 2022 seclog.log-20220501
-rw-r----- 1 root root 156K Mar 27 2022 seclog.log-20220326
-rw-r----- 1 root root 161K Mar 20 2022 seclog.log-20220319
-rw-r----- 1 root root 157K Mar 13 2022 seclog.log-20220312
-rw-r----- 1 root root 158K Mar 6 2022 seclog.log-20220305
-rw-r----- 1 root root 158K May 30 2021 seclog.log-20210529
-rw-r----- 1 root root 157K May 23 2021 seclog.log-20210522
-rw-r----- 1 root root 158K May 16 2021 seclog.log-20210515
-rw-r----- 1 root root 157K May 9 2021 seclog.log-20210508
-rw-r----- 1 root root 157K May 2 2021 seclog.log-20210501
-rw-r----- 1 root root 156K Mar 28 2021 seclog.log-20210326
-rw------- 1 root root 107K Mar 21 2021 seclog.log-20210319
drwx------. 3 root root 4.0K May 10 2022 samba
drwxr-xr-x. 2 root root 4.0K Nov 28 00:00 sa
drwxr-xr-x. 2 root root 4.0K Nov 27 03:19 rhsm
drwxr-xr-x 2 root root 4.0K Nov 12 20:31 rear
drwxr-xr-x 4 root root 4.0K Apr 16 2022 puppetlabs
drwxr-xr-x. 2 root root 4.0K Aug 17 2016 prelink
drwxr-xr-x 3 root root 4.0K Mar 11 2021 opsware
drwxr-xr-x. 2 ntp ntp 4.0K Jun 1 2020 ntpstats
-rw-r--r-- 1 root root 4.8K Mar 18 2021 ntp
-rw-r----- 1 root root 1.2M Nov 13 03:15 messages-20221113
-rw-r----- 1 root root 13M Aug 7 03:15 messages-20220807
-rw-r----- 1 root root 29M Jul 31 03:35 messages-20220731
-rw-r----- 1 root root 29M Jul 24 03:15 messages-20220724
-rw-r----- 1 root root 29M Jul 17 03:20 messages-20220717
-rw-r----- 1 root root 29M Jul 10 03:50 messages-20220710
-rw-r----- 1 root root 29M Jul 3 03:14 messages-20220703
-rw-r----- 1 root root 29M Jun 26 03:24 messages-20220626
-rw-r----- 1 root root 29M Jun 19 03:20 messages-20220619
-rw-r----- 1 root root 29M Jun 12 03:24 messages-20220612
-rw-r----- 1 root root 29M Jun 5 03:20 messages-20220605
-rw-r----- 1 root root 29M May 29 2022 messages-20220529
-rw-r----- 1 root root 29M May 22 2022 messages-20220522
-rw-r----- 1 root root 29M May 15 2022 messages-20220515
-rw-r----- 1 root root 29M May 8 2022 messages-20220508
-rw-r----- 1 root root 29M May 1 2022 messages-20220501
-rw-r----- 1 root root 29M Apr 24 2022 messages-20220424
-rw-r----- 1 root root 29M Apr 17 2022 messages-20220417
-rw-r----- 1 root root 29M Apr 10 2022 messages-20220410
-rw-r----- 1 root root 29M Apr 3 2022 messages-20220403
-rw-r----- 1 root root 29M Mar 27 2022 messages-20220327
-rw-r----- 1 root root 29M Mar 20 2022 messages-20220320
-rw-r----- 1 root root 29M Mar 13 2022 messages-20220313
-rw-r----- 1 root root 29M Mar 6 2022 messages-20220306
-rw-r----- 1 root root 29M Feb 27 2022 messages-20220227
-rw-r----- 1 root root 29M Feb 20 2022 messages-20220220
-rw-r----- 1 root root 29M Feb 13 2022 messages-20220213
-rw-r----- 1 root root 29M Feb 6 2022 messages-20220206
-rw-r----- 1 root root 29M Jan 30 2022 messages-20220130
-rw-r----- 1 root root 29M Jan 23 2022 messages-20220123
-rw-r----- 1 root root 29M Jan 16 2022 messages-20220116
-rw-r----- 1 root root 29M Jan 9 2022 messages-20220109
-rw-r----- 1 root root 29M Jan 2 2022 messages-20220102
-rw-r----- 1 root root 29M Dec 26 2021 messages-20211226
-rw-r----- 1 root root 29M Dec 19 2021 messages-20211219
-rw-r----- 1 root root 29M Dec 12 2021 messages-20211212
-rw-r----- 1 root root 29M Dec 5 2021 messages-20211205
-rw-r----- 1 root root 29M Nov 28 2021 messages-20211128
-rw-r----- 1 root root 29M Nov 21 2021 messages-20211121
-rw-r----- 1 root root 29M Nov 14 2021 messages-20211114
-rw-r----- 1 root root 29M Nov 7 2021 messages-20211107
-rw-r----- 1 root root 29M Oct 31 2021 messages-20211031
-rw-r----- 1 root root 29M Oct 24 2021 messages-20211024
-rw-r----- 1 root root 29M Oct 17 2021 messages-20211017
-rw-r----- 1 root root 29M Oct 10 2021 messages-20211010
-rw-r----- 1 root root 30M Oct 3 2021 messages-20211003
-rw-r----- 1 root root 31M Sep 26 2021 messages-20210926
-rw-r----- 1 root root 31M Sep 19 2021 messages-20210919
-rw-r----- 1 root root 30M Sep 12 2021 messages-20210912
-rw-r----- 1 root root 30M Sep 5 2021 messages-20210905
-rw-r----- 1 root root 30M Aug 29 2021 messages-20210829
-rw-r----- 1 root root 34M Aug 22 2021 messages-20210822
-rw-r----- 1 root root 34M Aug 15 2021 messages-20210815
-rw-r----- 1 root root 34M Aug 8 2021 messages-20210808
-rw-r----- 1 root root 34M Aug 1 2021 messages-20210801
-rw-r----- 1 root root 34M Jul 25 2021 messages-20210725
-rw-r----- 1 root root 34M Jul 18 2021 messages-20210718
-rw-r----- 1 root root 34M Jul 11 2021 messages-20210711
-rw-r----- 1 root root 34M Jul 4 2021 messages-20210704
-rw-r----- 1 root root 34M Jun 27 2021 messages-20210627
-rw-r----- 1 root root 34M Jun 20 2021 messages-20210620
-rw-r----- 1 root root 34M Jun 13 2021 messages-20210613
-rw-r----- 1 root root 32M Jun 6 2021 messages-20210606
-rw-r----- 1 root root 34M May 30 2021 messages-20210530
-rw-r----- 1 root root 34M May 23 2021 messages-20210523
-rw-r----- 1 root root 34M May 16 2021 messages-20210516
-rw-r----- 1 root root 34M May 9 2021 messages-20210509
-rw-r----- 1 root root 34M May 2 2021 messages-20210502
-rw-r----- 1 root root 34M Apr 25 2021 messages-20210425
-rw-r----- 1 root root 34M Apr 18 2021 messages-20210418
-rw-r----- 1 root root 34M Apr 11 2021 messages-20210411
-rw-r----- 1 root root 34M Apr 4 2021 messages-20210404
-rw-r----- 1 root root 34M Mar 28 2021 messages-20210328
-rw-r----- 1 root root 14M Mar 21 2021 messages-20210321
-rw-------. 1 root root 669K Mar 14 2021 messages-20210314
-rw-r--r--. 1 root root 140M Nov 28 09:11 lastlog
-rw------- 1 root root 106K Mar 18 2021 hawkey.log-20210321
-rw-r--r--. 1 root root 80K Mar 14 2021 hawkey.log-20210314
-rw------- 1 root root 0 Mar 21 2021 hawkey.log
-rw-r--r--. 1 root root 193 Dec 18 2020 grubby_prune_debug
-rw------- 1 root root 6.0K Mar 18 2021 dnf.rpm.log-20210321
-rw-r--r--. 1 root root 126K Mar 14 2021 dnf.rpm.log-20210314
-rw------- 1 root root 0 Mar 21 2021 dnf.rpm.log
-rw------- 1 root root 175K Mar 18 2021 dnf.log-20210321
-rw-r--r--. 1 root root 418K Mar 14 2021 dnf.log-20210314
-rw------- 1 root root 0 Mar 21 2021 dnf.log
-rw------- 1 root root 727K Mar 18 2021 dnf.librepo.log-20210321
-rw-r--r--. 1 root root 789K Mar 14 2021 dnf.librepo.log-20210314
-rw------- 1 root root 0 Mar 21 2021 dnf.librepo.log
-rw-r--r-- 1 root root 116K Nov 12 20:35 dmesg.old
-rw-r--r-- 1 root root 116K Nov 12 20:39 dmesg
-rw------- 1 root root 19M Nov 28 09:10 cron
drwxr-xr-x. 2 chrony chrony 4.0K Jan 10 2019 chrony
-rw------- 1 root root 21K Mar 19 2021 boot.log-20210319
-rw------- 1 root root 41K Mar 18 2021 boot.log-20210318
-rw------- 1 root root 42K Mar 12 2021 boot.log-20210312
drwx------. 2 root root 4.0K Nov 4 18:00 audit
drwxr-xr-x. 21 root root 4.0K Mar 11 2021 ..
";
// 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/