0

I have tons of this:

(278, 191, 825, 824, 3, <other code> ),
(282, 185, 326, 327, 4, <other code> ),
(284, 184, 545, 546, 3, <other code> ),
.
.
.
(314, 185, 340, 341, 4, <other code> ),

I want to add 0 at the end of the first number for each line

eg: (278, //rest of code ), to (2780, //rest of code ),

I'd managed to find match using regex: \(.+\, 1 will highlight eg:(278, 1 but dont know how to replace it to (2780, 1 for the rest of other numbers too

5 Answers5

1

You should be able to enter for "Find what":

\(([0-9]+)\,

For "Replace with":

\(\10,

The "\1" is the contents of the first capture group.

This works for me in Notepad++ using your example.

Edit

If you need a regex reference this is a pretty good one: https://stackoverflow.com/a/22944075/1684623

Of course you could make this more robust/cleaner by matching the start of line (^), using \d instead of [0-9], etc.

Community
  • 1
  • 1
Robert Harris
  • 482
  • 2
  • 6
1

If your file has consistently the format for each line of left bracket followed by 3 decimals and a comma, then an incredibly easy way to do this in Notepad++ is to use the "Column Editor" mode.

Do this by holding down the "Alt" key, and then click your left mouse button to highlight the comma all the way from top to bottom of the file, then once you've selected all the commas, press Alt+C to get the "Column / Multi-Selection Editor" to appear. Then enter Text to Insert as "0,", and click OK.

See my screenshot below:

Notepad Column Select

This should take you literally seconds. I've used it many times, and it will save you a lot of grief when doing tedious tasks like this.

Alvin Bunk
  • 7,106
  • 3
  • 26
  • 40
0

You need to insert ( and ) in the source regex, around the part you want to reuse, and insert \1 in the target regex to get it put there.

I can't say if your editor supports this, but that is the usual way

Aganju
  • 5,994
  • 1
  • 9
  • 22
0

You're going to need a capturing group

You then add brackets around the bit you want to use, and use \1 in your replace expression to use it.

Something like ^\(([0-9]+), as your find expression will do the trick, but your desired replace expression introduces a new problem. You'd want (\10,, but that may attempt to get the 10th capturing group, not the first one followed by a zero. That said, apparently many implementations do what you want, so this should suffice. Read more about that problem here.

Chris Kitching
  • 2,323
  • 18
  • 32
0

Using Notepad++ replace:

Find:         ^(\()(\d+)

Replace with: \1\20

\1 is the first match group; \2 is the second match group.

Quinn
  • 3,926
  • 2
  • 17
  • 17