Page MenuHomePhabricator

[Feature request] Add global flag to AWB's regex engine
Closed, DeclinedPublic

Description

Regex continues from the end of the last match by default. It would be useful in some cases to be able to have a global flag, which would allow the regex to find all possible matches. If implemented, this could be activated through a checkbox in AWB, next to the other (4?) checkbox settings.

Text to search

1212

Regex ("Find")

(\d).\1

Default result

Match 1:

  • Capture group 0: {121}
  • Capture group 1: {1}

Result without global flag

Match 1:

  • Capture group 0: {121}
  • Capture group 1: {1}

Match 2:

  • Capture group 0: {212}
  • Capture group 1: {2}

Event Timeline

Retro updated the task description. (Show Details)
Retro renamed this task from Regex matching continues from END of last match, instead of from next character to Regex matching continues from END of last match, instead of next position from BEGINNING of last match.Apr 1 2018, 5:22 AM
Retro closed this task as Invalid.EditedApr 1 2018, 5:49 AM

Never mind. I think this is the intended regex behavior. There are workarounds, so it's fine. There may be a flag that does my intended behavior in regex; more research is necessary.

I found out what I'm looking for: the global flag adds the behavior of finding every possible match. This would be useful in some cases, so it might be useful as a checkbox, but it should definitely not be on by default.

Retro triaged this task as Low priority.
Retro renamed this task from Regex matching continues from END of last match, instead of next position from BEGINNING of last match to [Feature request] Add global flag to AWB's regex engine.Apr 1 2018, 6:15 PM
Retro updated the task description. (Show Details)

Where do you want to actually use this? Result where? It's unclear what you're actually trying to do

@Reedy At the time, I was trying to match pairs of ref tags, like:

<ref name="ref1" />

...

<ref name="ref2" />

...

<references>
<ref name="ref1">ref1 content</ref>
<ref name="ref2">ref2 content</ref>
</references>

The issue was matching tags by name was overlapping, so a normal search wasn't working. However, lookarounds ended up working just fine.

I'm going to close this request because it seems rather silly to request AWB implement a niche regex flag that isn't even in C#; that would require more work and carry more costs than the minimal benefit it could offer.