This works
$ echo 31/03 | grep '[0-9\/]'
31/03
but this fails
$ echo 31/03 | rg '[0-9\/]'
Error parsing regex near '[0-9\/]' at character offset 5: Unrecognized escape sequence: '\/'.
$ rg --verison
ripgrep 0.4.0
I suspect it is because /
does not require actual escaping as it is not special character.
But it is most likely issue of regex, rather than ripgrep
Ah, looks like you are right.
$ echo 31/03 | grep '[0-9/]'
31/03
$ echo 31/03 | rg '[0-9/]'
1:31/03
In case anyone else lands on this: the underlying regex library is indeed to blame for this. The regex library is paranoid about which escape sequences it accepts so that additional escape sequences can be added in the future in a backwards compatible way.
With that said, permitting escape sequences like \/
or similar seems harmless, although it seems better to write regexes without escapes if possible.
I'm mixed on this thread. On one hand I enjoy not needing to escape things while doing regex with this beloved tool... but on the other, it'd make doing silly things like this...
rg 'unescaped regex' --files-with-matches | tr '\n' '\0' | xargs -0 sed -i -E 's/escaped regex find/escaped regex replace/g'
...able to use the same regex in both rg
and sed
without modifications, so that'd be the only real 'pros' point I can come up with. Either way, your creation has saved hours of my life, and I'm still finding new uses for it weekly, so thank you and please keep it going!
@blindside85 You may find the -F/--fixed-strings
flag useful.
Most helpful comment
I suspect it is because
/
does not require actual escaping as it is not special character.But it is most likely issue of regex, rather than ripgrep