Annotate RegEx for invalid-escape check

This commit is contained in:
RumovZ 2020-11-15 14:22:16 +01:00
parent a16d271eb0
commit a6628709c5

View File

@ -447,7 +447,15 @@ fn unescape_quotes(s: &str) -> Cow<str> {
fn is_invalid_escape(txt: &str) -> bool {
// odd number of \s not followed by an escapable character
lazy_static! {
static ref RE: Regex = Regex::new(r#"(^|[^\\])(\\\\)*\\([^\\":*_()]|$)"#).unwrap();
static ref RE: Regex = Regex::new(
r#"(?x)
(?:^|[^\\]) # not a backslash
(?:\\\\)* # even number of backslashes
\\ # single backslash
(?:[^\\":*_()]|$) # anything but an escapable char
"#
)
.unwrap();
}
RE.is_match(txt)