Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex substitution with Notepad++

I have a text file with several lines like these ones:

cd_cod_bus
nm_number_ex
cd_goal

And I want to get rid of the - and uppercase the following character using Notepad++ (I can also use other tool but if it doesn't get the problem more troublesome).

So I tried to get the characters with the following regex (?<=_)\w and replace it using \U\1\E\2 for the uppercasing trick but here is where my problems came. I think the regex is OK but once I click replace all I get this result:

cd_od_us
nm_umber_x
cd_oal

as you can see it is only deleting the match.

Do you know where the problem is?

Thanks.

like image 674
Averroes Avatar asked Sep 12 '13 08:09

Averroes


People also ask

How do you replace regex in Notepad?

Using Regex to find and replace text in Notepad++ In all examples, use select Find and Replace (Ctrl + H) to replace all the matches with the desired string or (no string). And also ensure the 'Regular expression' radio button is set.

How do you replace a value in Notepad?

Open the text file in Notepad. Click Edit on the menu bar, then select Replace in the Edit menu. Once in the Search and Replace window, enter the text you want to find and the text you want to use as a replacement.

How do I replace numbers in Notepad++?

In Notepad++ press Ctr+H to open the “Find and Replace” window. Under Search Mode: choose “Regular expression” and then check the “matches newline” checkbox. You should see closing </p> tags at the end of each line.


2 Answers

The search regex has no capture groups, i.e. the \1 and \2 references in the replacement do not refer to anything.

Try this instead:

Search: _(\w)
Replace \U\1\E

There you have a capture group in the search part (the parenthesis around the \w) and the \1 in the replacement refers back to what was captured.

like image 143
krisku Avatar answered Nov 03 '22 00:11

krisku


replace

_(.)

with

\U$1

will give you:

cdCodBus
nmNumberEx
cdGoal

and for your

I can also use other tool but if it doesn't get the problem more troublesome

I suggest you try vim.

like image 30
Kent Avatar answered Nov 02 '22 22:11

Kent