Skip to content

Add a flag for unescaped literal groups #1184

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

Closed
tgross35 opened this issue Apr 19, 2024 · 1 comment
Closed

Add a flag for unescaped literal groups #1184

tgross35 opened this issue Apr 19, 2024 · 1 comment

Comments

@tgross35
Copy link

Describe your feature request

Sometimes it would be helpful to have part of the regex query written as a literal, rather than escaping all regex-like syntax. For example, if you wanted to match exact const generics below with any function name:

foo::<{ FOO[1].len() }>();

Currently, the query must be written as \w+::<\{ FOO\[1]\.len\(\) \}>\(\); (some closing escapes optional).

With a new flag that allows for a plaintext group, this becomes easier to read and write. Choosing an arbitrary e for e xact:

\w+::(?e:<{ FOO[1].len() }>();)

I know of no prior art here but it seems like a relatively simple feature to help reduce mistakes, akin to verbose mode.

@BurntSushi
Copy link
Member

The prior art is \Q...\E. I'm generally opposed to it because it doesn't do what you think it does. In your example, the closing paranthesis is found well before your intended closing paranthesis. This is a general problem with the technique and I don't know how to avoid it.

Your better off just using regex::escape for literal parts and using standard interpolation facilities.

@BurntSushi BurntSushi closed this as not planned Won't fix, can't repro, duplicate, stale Apr 19, 2024
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

2 participants