简体   繁体   中英

replace second occurrence before character regular expression

I am trying to find a regex pattern that would allow me to replace the first occurrence of .N. with .C. before the equal sign of a text as below

.C.CA._Z._Z._Z.$._T._X.N.IAI=M.
.C.IN1._Z._Z._Z.$._T._X.N.IAI=M
.C.D4P._T.F._Z.$._T._X.N.FUNC=M
.C.D4P.D.F._Z.$._T._X.N.IAI=M.N
.C.D43S.D.F5._Z.$._T._X.N.RS=M.
.T.C.D43S.D.F5._Z.$._T._X.N.RS=
.C.D43S.D.F5._Z.$._T._X.N.OWLEM
.C.D4P.P.F._Z.$._T._X.N.IAI=M.N
.C.D41.O.FLA.T.$._T._X.N.OWLEM.
.T.C.D41.R.FLA.T.$.X1._X.N.OWLE
.A.FA._T.F._Z.$._T._X.N.FUNC=M.

How can I specify this pattern? Many thanks!

Search regex:

^([^=\n]*?)\.N\.

Replace by:

$1.C.

RegEx Demo

Make sure to use g (global) and m (multiline) flags.

You need to use a positive lookahead assertion.

([^=\n]*)\.N\.(?=[^=\n]*=)

Replace the matched .N. with .C.

DEMO

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