Hi all,
I crafted some regex ^[+-]{0,1}P([0-9]{1,}W)|([0-9]{1,}D){0,1}([0-9]{1,}H){0,1}([0-9]{1,}M){0,1}([0-9]{1,}S){0,1}
that should check iCal's 3.3.6. Duration iCalendar.org - 3.3.6. Duration
I checked ^[+-]{0,1}P([0-9]{1,}W)|([0-9]{1,}D){0,1}([0-9]{1,}H){0,1}([0-9]{1,}M){0,1}([0-9]{1,}S){0,1}
on https://regex101.com and there it does do as I expected and does not match ~P7W
, p7W
or P7w
.
When I use Rust's RegEx regex - Rust it changes:
use regex::Regex;
fn main() {
let r = Regex::new(r"^[+-]{0,1}P([0-9]{1,}W)|([0-9]{1,}D){0,1}([0-9]{1,}H){0,1}([0-9]{1,}M){0,1}([0-9]{1,}S){0,1}").unwrap();
assert!(r.is_match("+P15DT5H0M20S"));
assert!(r.is_match("-P15DT5H0M20S"));
assert!(r.is_match("P15DT5H0M20S"));
assert!(r.is_match("+P7W"));
assert!(r.is_match("-P7W"));
assert!(r.is_match("P7W"));
// no fail?!
assert!(!r.is_match("~P7W"));
assert!(!r.is_match("p7W"));
assert!(!r.is_match("P7w"));
}
Exited with status 101
Standard Error
Compiling playground v0.0.1 (/playground)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.35s
Running `target/debug/playground`
thread 'main' panicked at src/main.rs:11:9:
assertion failed: !r.is_match("~P7W")
Either my RexEx is wrong or I do not use Rust's RegEx correctly.
Can pls anybody give me a hint what is wrong here?