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

Open
elkebirmed opened this Issue Sep 17, 2016 · 16 comments

Comments

Projects
None yet
@elkebirmed

elkebirmed commented Sep 17, 2016

  • VSCode Version: 1.4.0
  • OS Version: Ubuntu 16.04

Steps to Reproduce:

  1. Ctrl+H
  2. Find camelCase strings ([a-z])([A-Z])
  3. Change it to lowercase $1-\L$1\E

expected fooBar to be foo-bar

@sandy081

This comment has been minimized.

Show comment
Hide comment
@sandy081

sandy081 Oct 3, 2016

Member

@elkebirmed May I know what are the standards/definitions for using \L and \E in your example?

Member

sandy081 commented Oct 3, 2016

@elkebirmed May I know what are the standards/definitions for using \L and \E in your example?

@elkebirmed

This comment has been minimized.

Show comment
Hide comment

elkebirmed commented Oct 4, 2016

@elkebirmed

This comment has been minimized.

Show comment
Hide comment
@elkebirmed

elkebirmed Oct 4, 2016

Let's say that we've this string:

Hello World

Capturing it with this RegEx: (Hello) (World)

Replacement is: \U1 \L2 will give us -> HELLO world

\U1 = $1 to Uppercase
\L2 = $2 to Lowercase

elkebirmed commented Oct 4, 2016

Let's say that we've this string:

Hello World

Capturing it with this RegEx: (Hello) (World)

Replacement is: \U1 \L2 will give us -> HELLO world

\U1 = $1 to Uppercase
\L2 = $2 to Lowercase
@sandy081

This comment has been minimized.

Show comment
Hide comment
@sandy081

sandy081 Oct 4, 2016

Member

@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

Member

sandy081 commented Oct 4, 2016

@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

@sandy081 sandy081 added this to the Backlog milestone Oct 4, 2016

@elkebirmed

This comment has been minimized.

Show comment
Hide comment
@elkebirmed

elkebirmed commented Oct 4, 2016

You're welcome @sandy081

@kdar

This comment has been minimized.

Show comment
Hide comment
@kdar

kdar Nov 27, 2017

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"

kdar commented Nov 27, 2017

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"
@alystair

This comment has been minimized.

Show comment
Hide comment
@alystair

alystair Jun 9, 2018

Ran into this today, seems regex replacement still isn't quite there yet.

alystair commented Jun 9, 2018

Ran into this today, seems regex replacement still isn't quite there yet.

@brianlowe

This comment has been minimized.

Show comment
Hide comment
@brianlowe

brianlowe Jun 11, 2018

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 commented Jun 11, 2018

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?

@retNull

This comment has been minimized.

Show comment
Hide comment
@retNull

retNull Jun 11, 2018

@brianlowe Notepad++ will do what you need.

retNull commented Jun 11, 2018

@brianlowe Notepad++ will do what you need.

@brianlowe

This comment has been minimized.

Show comment
Hide comment
@brianlowe

brianlowe Jun 12, 2018

@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.

brianlowe commented Jun 12, 2018

@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.

@freman

This comment has been minimized.

Show comment
Hide comment
@freman

freman Jun 26, 2018

I miss this from sublime :(

freman commented Jun 26, 2018

I miss this from sublime :(

@mesqueeb

This comment has been minimized.

Show comment
Hide comment
@mesqueeb

mesqueeb Jul 9, 2018

+1 for this functionality! I'm currently manually converting case on 100+ results in 50+ files... lol

mesqueeb commented Jul 9, 2018

+1 for this functionality! I'm currently manually converting case on 100+ results in 50+ files... lol

@Ugotsta

This comment has been minimized.

Show comment
Hide comment
@Ugotsta

Ugotsta Aug 20, 2018

As a temporary workaround, you can use a workflow like so:

  • Press CTRL-H (⌥⌘F on Mac).
  • Press ALT-R (⌥⌘R on Mac).
  • Type _([a-zA-Z]).
  • Press TAB and type $1.
  • Press ALT-ENTER (⌥ENTER on Mac).
  • Press F1 and type upper, then press ENTER.
  • Press CTRL-ALT-ENTER (⌥⌘ENTER on Mac).

A bit of explanation added here:
https://gist.github.com/2a271f6440f1ac7e028df55e94035e40

Ugotsta commented Aug 20, 2018

As a temporary workaround, you can use a workflow like so:

  • Press CTRL-H (⌥⌘F on Mac).
  • Press ALT-R (⌥⌘R on Mac).
  • Type _([a-zA-Z]).
  • Press TAB and type $1.
  • Press ALT-ENTER (⌥ENTER on Mac).
  • Press F1 and type upper, then press ENTER.
  • Press CTRL-ALT-ENTER (⌥⌘ENTER on Mac).

A bit of explanation added here:
https://gist.github.com/2a271f6440f1ac7e028df55e94035e40

@jpike88

This comment has been minimized.

Show comment
Hide comment
@jpike88

jpike88 Aug 21, 2018

@Ugotsta that workaround makes sense only to Windows users.

jpike88 commented Aug 21, 2018

@Ugotsta that workaround makes sense only to Windows users.

@jpike88

This comment has been minimized.

Show comment
Hide comment
@jpike88

jpike88 Aug 21, 2018

A more general workaround

  • Open find and enter the regex _[A-Za-z]
  • Open from top menu bar, Selection > Select all occurrences
  • Open command menu (⇧⌘P on Mac, Ctrl+Shift+P on Windows/Linux), then type 'Transform to Uppercase', hit enter.
  • Then press Left Arrow once, then Backspace once

jpike88 commented Aug 21, 2018

A more general workaround

  • Open find and enter the regex _[A-Za-z]
  • Open from top menu bar, Selection > Select all occurrences
  • Open command menu (⇧⌘P on Mac, Ctrl+Shift+P on Windows/Linux), then type 'Transform to Uppercase', hit enter.
  • Then press Left Arrow once, then Backspace once
@vbullinger

This comment has been minimized.

Show comment
Hide comment
@vbullinger

vbullinger Oct 4, 2018

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?

vbullinger commented Oct 4, 2018

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment