Skip to content
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

[Feature Request] Boost.regex - allow OR operator in look-behind #225

Open
Palloxin opened this issue Sep 12, 2024 · 1 comment
Open

[Feature Request] Boost.regex - allow OR operator in look-behind #225

Palloxin opened this issue Sep 12, 2024 · 1 comment

Comments

@Palloxin
Copy link

Palloxin commented Sep 12, 2024

Description

As the title says.

The lib doesnt accept OR operator in lookbehind.
Example:

/\w+(?<=Sublime|Bob)/

doesnt work.

BUT it accepts this:

/\w+(?<=Sublime)(?<=Bob)/

I would like the lib to support the OR operation for the regex look-behind

Other Details

These don't work too:

/\w+(?<=(?:Sublime|Bob))/
/\w+(?<=\s?Sublime)/
@mclow mclow transferred this issue from boostorg/boost Sep 12, 2024
@JohnAlt2
Copy link

JohnAlt2 commented Oct 30, 2024

ORs are accepted in lookbehinds so long as each branch is of the same length e.g.

/\w+(?<=Dave|John|.Bob)/

look-behinds needing to be fixed length is a known feature as documented e.g.: https://www.boost.org/doc/libs/1_86_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html

_Lookbehind
(?<=pattern) consumes zero characters, only if pattern could be matched against the characters preceding the current position (pattern must be of fixed length).

(?<!pattern) consumes zero characters, only if pattern could not be matched against the characters preceding the current position (pattern must be of fixed length)._

The desired functionality can often instead be created by using an OR of two separate look-behinds:

/\w+(?:(?<=Sublime)|(?<=Bob))/

Or adapt your branches to make them the same length such as:

/\w+(?<=Sublime|....Bob)/

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

No branches or pull requests

2 participants