Reputation: 397
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
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
Another option could be using capturing groups
(")g(\d+")
In the replacement use the 2 groups
$1k$2
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