1

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

gunr2171
  • 12,476
  • 25
  • 58
  • 80
FrankSharp
  • 2,452
  • 10
  • 36
  • 48
  • 2
    this post should help you http://stackoverflow.com/questions/6005609/replace-only-some-groups-with-regex – Dom Jul 08 '14 at 17:39

2 Answers2

6

Capture \d+ with a group and then for replacing, use $1 which means "Group 1" followed by E.

mystring= Regex.Replace(mystring, @"(\d+)IEME", "$1E"); 
Amit Joki
  • 56,285
  • 7
  • 72
  • 91
0

You should be using groups:

string mystring = "7IEME";
mystring= Regex.Replace(mystring, @"(\d+)IEME", "$1E"); 
Adriano Carneiro
  • 55,739
  • 12
  • 86
  • 122