0

Ok, before I get the "already answered", I have found and tried every permutation I found at:

While replacing using regex, How to keep a part of matched string?

Using Notepad++ Regex to Find and Replace Only Part of Found Text

I have these lines:

new MyObject("22222,11,21),
new MyObject("22223,12,22),
new MyObject("22224,13,23),
new MyObject("22225,14,24),

I'm trying to put the "end quote" around 22222, 22223, 22224 and 22225 for this:

new MyObject("22222",11,21),
new MyObject("22223",12,22),
new MyObject("22224",13,23),
new MyObject("22225",14,24),

The value I put into notepad++ for "Find What" is working (an escaped double quote plus 5 digits).

\"\d{5}

for "replace with" (based on what I found at the previous two SOF articles), i have tried:

(these are just to test it)

aaa$1bbb
aaa$1$2bbb
aaa$1$2$3bbb

and

aaa\1bbb
aaa\1\2bbb
aaa\1\2\3bbb

Obviously, what I want (and what I think should work) is below (escaped double-quote, then the placeholder for "1", and the a second escaped double-quote)

\"\1\"\

or

\"$1\"\

My search mode is "regular express" and I've toggled ".matches newline" on and off.

Notepad++ v7.7.1 (64-bit)

granadaCoder
  • 23,729
  • 8
  • 95
  • 129

2 Answers2

2

No needs for capture group here, use the following:

  • Ctrl+H
  • Find what: "\d{5}\K
  • Replace with: "
  • check Wrap around
  • check Regular expression
  • Replace all

Explanation:

"           # a double quote
\d{5}       # 5 digits
\K          # forget all we have seen until this position

Result for given example:

new MyObject("22222",11,21),
new MyObject("22223",12,22),
new MyObject("22224",13,23),
new MyObject("22225",14,24),

Screen capture:

enter image description here

Toto
  • 86,179
  • 61
  • 85
  • 118
1

You need to capture the match in a capture group:

(\"\d{5})

The replace it with the captured value and a quote:

\1"

e.g.

enter image description here

zzevannn
  • 2,859
  • 1
  • 11
  • 20