Skip to content

Instantly share code, notes, and snippets.

@jasonyost
Created July 23, 2010 01:49
Show Gist options
  • Save jasonyost/486900 to your computer and use it in GitHub Desktop.
Save jasonyost/486900 to your computer and use it in GitHub Desktop.
Regex rxnum = new Regex(@"(\d+(?! */))? *-? *(?:(\d+) */ *(\d+))?.*$");
Match numMatch = rxnum.Match(ingredient);
if (numMatch.Success)
{
amount = (!string.IsNullOrEmpty(numMatch.Groups[1].Value) ? numMatch.Groups[1].Value : string.Empty) + (!string.IsNullOrEmpty(numMatch.Groups[2].Value) ? " " + numMatch.Groups[2].Value + "/" + numMatch.Groups[3].Value : string.Empty);
// do something with the amount...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment