简体   繁体   中英

Regex.Replace just part of regex

I made this line of code

mystring= Regex.Replace(mystring, @"\d+IEME", "E"); 

But got a problem because I want to keep the number. Like 7IEME replace to 7E

用一个组捕获\\d+ ,然后替换,使用$1表示“ Group 1”,后跟E

mystring= Regex.Replace(mystring, @"(\d+)IEME", "$1E"); 

You should be using groups:

string mystring = "7IEME";
mystring= Regex.Replace(mystring, @"(\d+)IEME", "$1E"); 

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