Taking a few tentative steps into regex. Given this string -
"Northamptonshire T20 251/10 v Yorkshire T20 136/10 & 237 *"
I want to match "251/10 " and "136/10 " and "& 237 *" so I can remove them.
In these two regex testers -
http://www.regexr.com/ and
http://regexpal.com/
the pattern "\d+\/\d+\s|\&\s\d+\s\*" does the trick but when I try in C#
var newString = Regex.Replace(s,@"\d+\/\d+\s|\&\s\d+\s\*","");
it doesn't remove the final part "& 237 *"
Are there differences in the .net implementation? Anyone give a hint as
to where I'm going wrong?
mick
NOT an expert on Regex!!!
Using Expresso I get this code
private static void Main(string[] args)
{
Regex MyRegex = new Regex(
"\\d+\\/\\d+\\s|\\&\\s\\d+\\s\\*",
RegexOptions.IgnoreCase
| RegexOptions.CultureInvariant
| RegexOptions.IgnorePatternWhitespace
| RegexOptions.Compiled
);
string InputText = "Northamptonshire T20 251/10 v Yorkshire
T20 136/10 & 237 *";
string MyRegexReplace = string.Empty;
// Replace the matched text in the InputText using the
replacement pattern
string result = MyRegex.Replace(InputText, MyRegexReplace);
}
and it works! Leaves a blank last but...
Taking a few tentative steps into regex. Given this string -
"Northamptonshire T20 251/10 v Yorkshire T20 136/10 & 237 *"
I want to match "251/10 " and "136/10 " and "& 237 *" so I can remove them.
In these two regex testers -
http://www.regexr.com/ and
http://regexpal.com/
the pattern "\d+\/\d+\s|\&\s\d+\s\*" does the trick but when I try in C#
var newString = Regex.Replace(s,@"\d+\/\d+\s|\&\s\d+\s\*","");
it doesn't remove the final part "& 237 *"
Are there differences in the .net implementation? Anyone give a hint as
to where I'm going wrong?
mick
NOT an expert on Regex!!!
Using Expresso I get this code
private static void Main(string[] args)
{
Regex MyRegex = new Regex(
"\\d+\\/\\d+\\s|\\&\\s\\d+\\s\\*",
RegexOptions.IgnoreCase
| RegexOptions.CultureInvariant
| RegexOptions.IgnorePatternWhitespace
| RegexOptions.Compiled
);
string InputText = "Northamptonshire T20 251/10 v Yorkshire
T20 136/10 & 237 *";
string MyRegexReplace = string.Empty;
// Replace the matched text in the InputText using the
replacement pattern
string result = MyRegex.Replace(InputText, MyRegexReplace);
}
and it works! Leaves a blank last but...