Started with regex/program.

This commit is contained in:
vorboyvo 2024-12-27 14:21:30 -05:00
parent d66849e42f
commit 1c4e976562
2 changed files with 18 additions and 0 deletions

View file

@ -4,3 +4,4 @@ version = "0.1.0"
edition = "2021"
[dependencies]
regex = "1.11.1"

View file

@ -0,0 +1,17 @@
use regex::Regex;
fn slug_from_link(link: String) -> Result<String, String> {
let re = Regex::new(r"\.wikipedia\.org\/wiki\/|\?").unwrap();
let v: Vec<&str> = re.split(&link).collect();
println!("{v:?}");
if v.len() >= 2 { Ok(v[1].to_string()) } else { Err("Illegal link {link} provided".to_string()) }
}
mod tests {
use super::*;
#[test]
fn test_slug_from_link_1() {
assert_eq!(slug_from_link("https://en.wikipedia.org/wiki/Buck-a-beer?wprov=sfla1".to_string()).unwrap().as_str(), "Buck-a-beer")
}
}