Skip to content

Matching non-backslash characters #766

Answered by BurntSushi
billminckler asked this question in Q&A
Discussion options

You must be logged in to vote

than wouldn't . as well?

Yes. If you try compiling (?i)(^\w+:\\){1}Users\\[\\]+?\\AppData\\Local\\.* without any other changes, then you'll get this error:

regex parse error:
    (?i)(^\w+:\\){1}Users\\[\\]+?\\AppData\\Local\\.*
                                                   ^
error: pattern can match invalid UTF-8

Let's take a look at how you're building the regex:

    let r1 = RegexBuilder::new(REGEX_TEST)
        .unicode(false)
        .build()
        .expect("Failed to compile regular expression");

When unicode is disabled (which you could also do with (?-u) or (?i-u) in your case), then everything in the regex that was Unicode aware becomes a simple operation on bytes. So in…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@billminckler
Comment options

Answer selected by billminckler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants