Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace only part of found text?

Tags:

I have a file with a some comma separated names and some comma separated account numbers.
Names will always be something like Dow, John and numbers like 012394,19862.

Using Notepad++'s "Regex Find" feature, I'd like to replace commas between numbers with pipes |.

Basically :

turn:  Dow,John      into:  Dow,John        12345,09876          12345|09876        13568,08642          13568|08642 

I've been using [0-9], to find the commas, but I can't get it to properly leave the number's last digit and replace just the comma.

Any ideas?

like image 614
JToland Avatar asked Oct 31 '12 18:10

JToland


People also ask

How do I find and replace a pattern 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.

Can I use regex in replace?

How to use RegEx with . replace in JavaScript. To use RegEx, the first argument of replace will be replaced with regex syntax, for example /regex/ . This syntax serves as a pattern where any parts of the string that match it will be replaced with the new substring.

How do you use Find and Replace in regex?

Find/Replace with Regular Expression (Regex) or Wildcards. Word supports find/replace with it own variation of regular expressions (regex), which is called wildcards. To use regex: Ctrl-H (Find/Replace) ⇒ Check "Use wildcards" option under "More".


2 Answers

Search for ([0-9]), and replace it with \1|. Does that work?

like image 179
Joshua Dwire Avatar answered Sep 24 '22 15:09

Joshua Dwire


use this regex

(\d),(\d) 

and replace it with

$1|$2 

OR

\1|\2 
like image 41
Anirudha Avatar answered Sep 23 '22 15:09

Anirudha