Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to transform a matched group when doing a find/replace?

Consider the following list of words:

targetX
targetY
targetZ
targetColor
targetWidth

I want to remove the "target" prefix, while maintaining the naming convention. This means that the first character after the prefix needs to be downcased:

x
y
z
color
width

So far I can match the text that I want and group the characters accordingly:

Find:    "target[A-Z]"
Replace: ???

But I don't know what I can do for the replace. Is there a regex substitution function that can do this in Visual Studio, or an alternative editor?

like image 718
Karl Nicoll Avatar asked Nov 28 '25 07:11

Karl Nicoll


1 Answers

Visual Studio S&R tool does not support upper-/lowercasing operators in the replacement part. The work around is to use Notepad++ or SublimeText with

Find: \btarget([A-Z])
Replace with: \l$1

Here, \btarget will match a word starting with target and ([A-Z]) will match and capture an uppercase ASCII letter into Group 1 that will later refernce with a $1 backreference and turn it lowercase with \l operator.

like image 159
Wiktor Stribiżew Avatar answered Nov 29 '25 22:11

Wiktor Stribiżew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!