changjx
changjx

Reputation: 397

How to replace strings only in the string and numbers combination between double quotation Notepad++?

I'm trying to replace 「g」 with 「k」 in some article :

this is "g1"..., and  "g2" is......, last "g1034" shows that...

the end result will be

this is "k1"..., and  "k2" is......, last "k1034" shows that...

I'm using the following regex to find the pattern :

"([^"]*)"

but fail to replace with success.

How can I do a replacement? thx in advance

Upvotes: 2

Views: 74

Answers (1)

The fourth bird
The fourth bird

Reputation: 163642

One option is to use

"\Kg(?=\d+")
  • " Match "
  • \Kg Forget what is currenly matched using \K, then match g
  • (?=\d+") Positive lookahead, assert what is on the right is 1+ digits and "

And replace with k

Regex demo


Another option could be using capturing groups

(")g(\d+")

In the replacement use the 2 groups

$1k$2

Regex demo

Note that if you do not want to match only digits, you could use [^"]+ instead of \d+ to match at least 1 char after g or use * to match 0 or more chars after g

Upvotes: 1

Related Questions