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] Allow forward slash (/) to be optionally escaped in patterns #1902

Closed
comex opened this issue Jun 17, 2021 · 2 comments
Closed
Labels
enhancement An enhancement to the functionality of the software.

Comments

@comex
Copy link

comex commented Jun 17, 2021

Describe your feature request

Many languages use / to indicate the start and end of a regular expression, and thus require any forward slashes within the pattern to be escaped as \/.

ripgrep does not need to explicitly delimit regexes, and does not treat / as special. But sometimes habit leads me to mistakenly type \/ anyway. This produces an error:

regex parse error:
    \/foo
    ^^
error: unrecognized escape sequence

Fair enough. But given ripgrep's status as an interactive tool, it would be nice if it would just Do What I Mean, perhaps warning about the unnecessary escape but then proceeding, rather than making me go back and edit the command.

I tested various other regular expression APIs and tools that don't use / as a delimiter: Python re, PCRE, GNU grep, and BSD grep on macOS. All of these accepted \/ (with no warning) and treated it as /. (Most of those seemed to allow unnecessary backslash escapes of arbitrary characters; Python allowed it for characters other than letters and numbers. Personally I'd prefer a more conservative approach that only allows it for /.)

@BurntSushi
Copy link
Owner

This is better tracked here: rust-lang/regex#501

While I suppose ripgrep could allow this independently of what the regex engine does, it would probably be more trouble than it's worth.

@BurntSushi BurntSushi added the enhancement An enhancement to the functionality of the software. label Jun 17, 2021
@comex
Copy link
Author

comex commented Jun 17, 2021

Aha.

@comex comex closed this as completed Jun 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement to the functionality of the software.
Projects
None yet
Development

No branches or pull requests

2 participants