简体   繁体   English

仅在字符串后跟某些字符时替换字符串中的空格

[英]Replace space in string only if followed by certain characters

Im trying to replace all spaces in a string only if they are followed by a certain number os characters. 我试图替换字符串中的所有空格,除非它们后跟一定数量的os字符。 My example: 我的例子:

DKR N872 DEMIR UN872 DENOX UZ319 MOPIL
DKR DEMIR DENOX MOPIL TRS N866 ELTOK

Current output: 电流输出:

DKR N872 DEMIR UN872 DENOX UZ319 MOPIL
DKR DCT DEMIR DENOX DCT MOPIL TRS N866 ELTOK

What i want is: 我想要的是:

DKR N872 DEMIR UN872 DENOX UZ319 MOPIL
DKR DCT DEMIR DCT DENOX DCT MOPIL DCT TRS N866 ELTOK

My regex: 我的正则表达式:

(?<fix1>[A-Z]{3,5}) (?<fix2>[A-Z]{3,5})

Replacement:
$1 DCT $2

As you can se, in my current output it skips the parts that's hase already been "involved" in the last replace. 如您所知,在当前输出中,它会跳过上次替换中已“涉及”的部分。 Like between DEMIR & DENOX. 就像DEMIR和DENOX之间。

Please help 请帮忙

您几乎就到了(?<fix1>[AZ]{3,5}) (?<fix2>(?=[AZ]{3,5}))$1 DCT $2替换$1 DCT $2注意(?<fix1>[AZ]{3,5}) (?<fix2>(?=[AZ]{3,5}))运算符?=

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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