Find and Replace RegEx question
Posted
by fraXis
on Stack Overflow
See other posts from Stack Overflow
or by fraXis
Published on 2010-05-10T22:06:45Z
Indexed on
2010/05/10
22:24 UTC
Read the original article
Hit count: 441
I am starting to get a grip on RegEx thanks to all the great help here on SO with my other questions. But I am still suck on this one:
My code is:
StreamReader reader = new StreamReader(fDialog.FileName.ToString());
string content = reader.ReadToEnd();
reader.Close();
I am reading in a text file and I want to search for this text and change it (the X and Y value always follow each other in my text file):
X17.8Y-1.
But this text can also be X16.1Y2.3 (the values will always be different after X and Y)
I want to change it to this
X17.8Y-1.G54
or
X(value)Y(value)G54
My RegEx statement follows but it is not working.
content = Regex.Replace(content, @"(X(?:\d*\.)?\d+)*(Y(?:\d*\.)?\d+)", "$1$2G54");
Can someone please modify it for me so it works and will search for X(wildcard) Y(Wildcard) and replace it with X(value)Y(value)G54?
© Stack Overflow or respective owner