re = /(^([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))/mi
str = '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'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
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 Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html