-
Notifications
You must be signed in to change notification settings - Fork 28.4k
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
Enable regular expression case changing #12185
Comments
@elkebirmed May I know what are the standards/definitions for using \L and \E in your example? |
Let's say that we've this string:
Capturing it with this RegEx: Replacement is:
|
@elkebirmed Thanks for the documentation. This is cool to have. This is beyond the scope of what is currently supported by javascript. We need to come up with our own advanced replace engine to support these cases. Thanks |
You're welcome @sandy081 |
It would be nice to have a way to supply a javascript function to the capture groups, so we can choose how to transform them and do more things than just upper/lower case. Since javascript already provides this, we just need an interface for it. "some_VAR".replace(/([a-z]+)_([A-Z]+)/, function(match, p1, p2) {
return [p1.toUpperCase(), p2.toLowerCase()].join("_");
})
// "SOME_var" |
Ran into this today, seems regex replacement still isn't quite there yet. |
Ran into this today. Anyone know of an online tool which supports case conversion in regex replacement - just to save me having to install SublimeText just for this task, while waiting for VSCode to catch up? |
@BrianLowe Notepad++ will do what you need. |
@retnull Thanks. Notepad++ does the casing transformation. (Now I just need to work up a suitably selective expression and corresponding substitution to complete my task. |
I miss this from sublime :( |
+1 for this functionality! I'm currently manually converting case on 100+ results in 50+ files... lol |
As a temporary workaround, you can use a workflow like so:
A bit of explanation added here: |
@Ugotsta that workaround makes sense only to Windows users. |
A more general workaround
|
This issue is over two years old and sounds really easy to fix and useful. Can we get an update or roadmap on this, please? |
Is this possible, i.e. worth roadmapping, now that PCRE2 is an option, as of v1.29.0?
|
Would you be able to provide a link? |
Text Transformer For VS Code I don't remember remember which extension I use or if it's a feature now, the command I use from the command palette is 'Transform to' |
Those extensions don't quite meet the need. Vscode already has case transformation natively, but something you can't do is regex find across multiple files and replace the found items with upper or lower case all at once. |
Eg: Search: Use case: Converting structures to go |
I like this awesome feature, and sometimes I need to use this feature like replace all the tag name of html to lowercase if possible. |
Is any updates for this issue? |
That MS are not attending to this basic and important feature suggests that VSCode may be deprecated soon in favor of some other code editor. Shame, I quite liked VSCode. |
Somehow I doubt it. 😉 |
We could take a PR for this if anyone wants to work on it. I think we would want something basically consistent with another implementation: https://www.regular-expressions.info/replacecase.html but we can only support it for 'replace', not for searching with backreferences like Perl apparently supports. If someone wants to work on it, please let's talk about how it would work first 😁 |
Do you have a cost code we can invoice against?
With Regards,
Mr Sholto Maud
… On 26 Feb 2020, at 05:16, Rob Lourens ***@***.***> wrote:
We could take a PR for this if anyone wants to work on it. I think we would want something basically consistent with another implementation: https://www.regular-expressions.info/replacecase.html but we can only support it for 'replace', not for searching with backreferences like Perl apparently supports. If someone wants to work on it, please let's talk about how it would work first 😁
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
|
It seems like not being able to change case using regex is an upstream issue. I hope by going through chmln/sd#72 (comment) & BurntSushi/ripgrep#1546 (comment) you will be able to understand what is the problem and what might be the solution. |
It's not upstream, replacement is implemented in VS Code, not ripgrep. |
@roblourens which regex flavour are you using for replacement? |
@roblorens Search and replace is implemented differently in at least three places in VSCode. As @blueray453 mentions, the global S&R seems to be implemented with ripgrep, which only "accidentally" supports replace and has no plans to add replacement features. So even if someone wanted to contribute the time to ripgrep, it likely wouldn't get merged. And the cost of revamping and unifying VSCode's various search implementations is a bit larger than most third-party PRs. And I'm not holding my breath. ;) That said, I do have a draft PR #96128 (!) that I may spend more time on if there's interest (I'm not a Node guy). In my case I had mostly a single very long file I wanted to S&R, so "at least I'm okay". ;-) |
Merged this for the find widget - work to do this for search is still ongoing. |
Steps to Reproduce:
Ctrl+H
([a-z])([A-Z])
$1-\L$1\E
expected
fooBar
to befoo-bar
The text was updated successfully, but these errors were encountered: