Skip to content

Instantly share code, notes, and snippets.

@anytizer
Created October 19, 2021 18:04
Show Gist options
  • Save anytizer/21ffcd2809efbeeba6737c6633cab7bf to your computer and use it in GitHub Desktop.
Save anytizer/21ffcd2809efbeeba6737c6633cab7bf to your computer and use it in GitHub Desktop.
Regular Expression pattern match
int nominator = Nominiators.FOUR;
int denominator = Denominators.FOUR;
int tempo = Tempos.ONEFOURTY;
FileInfo fi = new FileInfo(filename);
string pattern = @"^filename-(\d+)-(\d+)-(\d+)\.txt$";
Regex re = new Regex(pattern);
Match chunks = re.Match(fi.Name);
if(chunks.Groups.Count == 4)
{
nominator = int.Parse(chunks.Groups[1].Value);
denominator = int.Parse(chunks.Groups[2].Value);
tempo = int.Parse(chunks.Groups[3].Value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment