Open
Description
Please tick this box to confirm you have reviewed the above.
- I have a different issue.
What version of ripgrep are you using?
ripgrep 14.0.3
How did you install ripgrep?
Using ripgrep_14.0.3-1_amd64.deb
What operating system are you using ripgrep on?
Ubuntu 20.04
Describe your bug.
Using (?x)
to add comments isn't working due to automatic wrapping of the supplied pattern within (?:)
.
What are the steps to reproduce the behavior?
Any pattern which uses (?x)
and a comment.
What is the actual behavior?
$ echo 'fig a#b 123' | rg -o '(?x)\d+ #extract digits'
regex parse error:
(?:(?x)\d+ #extract digits)
^
error: unclosed group
What is the expected behavior?
I think automatic wrapping of patterns inside non-capturing group was introducted for this issue: #2480. If possible, don't modify the pattern when there's a comment. Or may be add a note in the documentation for this corner case.
FWIW, GNU grep
doesn't support multiple patterns via -e
or -f
for PCRE:
$ echo 'fig a#b 123' | grep -oP '(?x)\d+ #extract digits'
123
$ echo 'MyText' | grep -P -e '(?i)notintext' -e 'text'
grep: the -P option only supports a single pattern