Skip to content

Erroneous failure to match in simple regex #289

Closed
@ConnorGray

Description

@ConnorGray

The simple regexes ((IMG|MVI|MGG)|DS)X and (((IMG|MVI)|MG)|DS)X both ought to match the string "MVIX, but only the second one does.

extern crate regex;

use regex::{Regex};

fn main() {
    simple_match_1();
    simple_match_2();
}

/// This example working on regex101: https://regex101.com/r/WJgwJ5/1
#[test]
fn simple_match_1() {
    let regex_str = "((IMG|MVI|MG)|DS)X";
    let text = "MVIX";

    let regex: Regex = Regex::new(regex_str).unwrap();

    // These both panic when they shouldn't
    assert!(regex.is_match(text));
    assert!(regex.find(text) != None);
}

/// This example *does not* panic
#[test]
fn simple_match_2() {
    let regex_str = "(((IMG|MVI)|MG)|DS)X";
    let text = "MVIX";

    let regex: Regex = Regex::new(regex_str).unwrap();

    // These both *work* (no panic)
    assert!(regex.is_match(text));
    assert!(regex.find(text) != None);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions