using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"(^([0-9[:punct:]0-9]+|\p{No}|\d\p{No}) ?\s* ?([0-9[:punct:]0-9]+|\p{No}|\d\p{No})* ?\w* (cup|tsp|tbps|tablespoon|teaspoon|small|medium|pint|ounce|pound))|(^(small|Large|medium|Fresh))";
string input = @"Should match:
1 Cups
2 tsp
3 tbps
1/2 tablespoon
3 tablespoons
1 tablespoon
3 teaspoons
1 small
Small chiles
23 Small chiles
1/2 a Small chile
1 1/2 cups kewpie
11/2 cups kewpie
1/3 cup fresh lemon juice
1 medium onion
Large
medium
Freshly
1½ cups Kewpie
½ cups Kewpie
1 pint
4 ounces
1 pound
2 pounds
Should not match:
1 Make the sauce
1 toast the bread
I want to make 1 piece of toast";
RegexOptions options = RegexOptions.Multiline | RegexOptions.IgnoreCase;
foreach (Match m in Regex.Matches(input, pattern, options))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
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