Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Notepad++ Replace regex match for same text plus appending character

I have a file with text and numbers with a length of 5 (i.e. 12000, 11153, etc.). I want to append all of these numbers with a 0. So 11153 becomes 111530. Is this possible in Notepad++?

I know I can find all numbers with the following regex: [0-9]{5}, but how can I replace these with the same number, plus an appending 0?

In the replacement box I tried the following things:

  • [0-9]{5}0 - Which it took literally, so 11153 was replaced with [0-9]{5}0
  • \10 - I read somewhere that \1 would take the match, but it doesn't seem to work. This will replace 11153 with 0
  • EDIT: \00 - Based on this SO answer I see I need to use \0 instead of \1. It still doesn't work though. This will replace 11153 with

So, I've got the feeling I'm close with the \1 or \0, but not close enough.

like image 215
Kevin Cruijssen Avatar asked Mar 14 '16 09:03

Kevin Cruijssen


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 I replace a character 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 you remove text before or after a specific character in Notepad++?

Do you want to delete everything before the | and including the | character. You can try find: (. +\|) and leave replace empty.


2 Answers

You are very near to the answer! What you missed is a capturing group.

Use this regex in "Find what" section:

([0-9]{5})

In "Replace with", use this:

\10

The ( and ) represent a capturing group. This essentially means that you capture your number, and then replace it with the same followed by a zero.

like image 84
CinCout Avatar answered Oct 20 '22 08:10

CinCout


You are very close. You need to add a capturing group to your regex by surrounding it with brackets. ([0-9]{5})

Then use \10 as the replacement. This is replacing the match with the text from group 1 followed by a zero.

like image 8
roblovelock Avatar answered Oct 20 '22 07:10

roblovelock