简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM