Skip to content

The regex parse error while the expre is correct ! #1171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
GostGrimmy opened this issue Mar 7, 2024 · 2 comments
Closed

The regex parse error while the expre is correct ! #1171

GostGrimmy opened this issue Mar 7, 2024 · 2 comments
Labels

Comments

@GostGrimmy
Copy link

Thanks for your work

Thanks you for this project, I am a new one study rust, I use this lib have some problem.

regex version

1.10.3

code

use regex::Regex;

#[test]
fn test_is_email() {
    // let a = is_email(&"[email protected]".to_string());
    // assert_eq!(a, true);
    let r = Regex::new(r"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$").unwrap();
    let aa = r.is_match("[email protected]");
    assert_eq!(aa,true)
}

The output in termainal

running 1 test
thread 'tests::form_test::test_is_email' panicked at src/tests/form_test.rs:9:61:
called `Result::unwrap()` on an `Err` value: Syntax(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
regex parse error:
    ^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$
      ^^
error: invalid range boundary, must be a literal
@BurntSushi
Copy link
Member

The regex is not valid. The error message is both telling you the problem and pointing you to where it occurs. A - in a character class indicates a range. Both sides of a range must be a literal character (or absent, i.e., adjacent to the open or close of a class as in [\w-]), but \w is itself another character class. You likely either want [\w\-.] or [-\w.]. Incidentally, your escaping of . inside a character class is superfluous because a . has no special meaning inside of a class.

@BurntSushi BurntSushi closed this as not planned Won't fix, can't repro, duplicate, stale Mar 7, 2024
@GostGrimmy
Copy link
Author

Thanks very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants