Skip to content

Unexpected Match Order with Regular Expression #448

@tanjt107

Description

@tanjt107

Hello,

I am using re2 in conjunction with Google BigQuery and am experiencing unexpected match order results from a regular expression operation.

Here is the regular expression I am using: .*(?i)(foo|bar).*

I am applying this regular expression to the following strings:
String 1: "foo bar"
String 2: "bar foo"

My understanding of regular expressions leads me to expect "foo" to be the first match in both cases, as it precedes "bar" in both the regular expression and the test strings.

However, the actual results I'm seeing are:
For String 1 ("foo bar"), the match is "bar"
For String 2 ("bar foo"), the match is "foo"

I am trying to understand why the match order appears to be reversed from what I expect. Does re2 handle regular expression matching differently than other engines? Is there a way I can modify the regular expression or use a different function to achieve the expected order?

Thank you in advance for any insights you can provide.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions