Giter Club home page Giter Club logo

Comments (1)

iwillspeak avatar iwillspeak commented on June 16, 2024

I can reproduce this:

use onig::Regex;

fn main() {
    test("Greater|GreaterOrEqual");
    test("GreaterOrEqual|Greater");
}

fn test(regex_string: &str) {
    let re = Regex::new(regex_string).unwrap();
    println!("Regex: {regex_string}");
    check(&re, "Greater");
    check(&re, "GreaterOrEqual");
}

fn check(regex: &Regex, input: &str) {
    let matched = regex.is_match(input);
    println!("Input: {input} = {matched}");
}

This seems to be caused by the way that is_match works. We first match the regex against the text, and then check
that the whole text was matched. In this case the order of the alternation changes what Oniguruma matches. If the
GreaterOrEqual is first then we match the longer item. if Greater is first then we only match that. This then means
that the expression hasn't matched the whole input text causing the behaviour you're seeing.

There's an option for Oniguruma which should allow us to force it to choose the longest match, but setting it either
with (?L) in the pattern or via RegexOptions::::REGEX_OPTION_FIND_LONGEST doesn't seem to affect the
outcome.

from rust-onig.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.