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

Unrecognized escape sequence: '\/' #434

Closed
tekumara opened this issue Apr 2, 2017 · 5 comments
Closed

Unrecognized escape sequence: '\/' #434

tekumara opened this issue Apr 2, 2017 · 5 comments

Comments

@tekumara
Copy link

tekumara commented Apr 2, 2017

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
@DoumanAsh
Copy link
Contributor

DoumanAsh commented Apr 2, 2017

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

@tekumara
Copy link
Author

tekumara commented Apr 2, 2017

Ah, looks like you are right.

$ echo 31/03 | grep '[0-9/]'
31/03
$ echo 31/03 | rg '[0-9/]'
1:31/03

@tekumara tekumara closed this as completed Apr 2, 2017
@BurntSushi
Copy link
Owner

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.

@blindside85
Copy link

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!

@BurntSushi
Copy link
Owner

@blindside85 You may find the -F/--fixed-strings flag useful.

jgonera added a commit to jgonera/dotfiles that referenced this issue Mar 24, 2020
`/` is commonly used in paths and requires escaping in `sed` but not in
`rg` which makes using it tricky
(BurntSushi/ripgrep#434).
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

4 participants