using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"([0-9]+)(?:-([0-9]+)|\s*over)";
string substitution = @"";
string input = @"'m trying to match speed descriptions of highway tickets, for example,text lines:
""L A 16-25MPH"" should return 2 groups: 16, 25
""LIMITED ACCESS SPEED I-75"" should return no matches.
""LMT ACC 6-10"" should return 2 groups: 6, 10
""6 OVER"" should return 1 group: 6
I'm OK with all of the above situations, but I run into issues for strings with numbers that aren't related to speed, for example:
";
RegexOptions options = RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace;
Regex regex = new Regex(pattern, options);
string result = regex.Replace(input, substitution);
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx