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
  • 16,104
  • 25
  • 61
  • 88
FrankSharp
  • 2,552
  • 10
  • 38
  • 49
  • 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
  • 58,320
  • 7
  • 77
  • 95
0

You should be using groups:

string mystring = "7IEME";
mystring= Regex.Replace(mystring, @"(\d+)IEME", "$1E"); 
Adriano Carneiro
  • 57,693
  • 12
  • 90
  • 123