Created
April 20, 2021 14:44
-
-
Save Bas-Man/dbdff9835e0106e3e3b6a2890443e948 to your computer and use it in GitHub Desktop.
Regex to match Mechanism type A for SPF using Rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let regex = regex::Regex::new(r"(?P<a_only>a$)|(?:a:)(?P<a_colon>[^/].+)|(?P<a_slash>a/\d{1,2})").unwrap(); | |
[ | |
"a", | |
"a:example.com", | |
"a:mailers.example.com", | |
"a/24", | |
"a:offsite.example.com/24]", | |
] | |
.iter() | |
.copied() | |
.map(|string| regex.captures(string)) | |
.for_each(|cap| println!("{:?}", cap)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment