Created
October 19, 2021 18:04
-
-
Save anytizer/21ffcd2809efbeeba6737c6633cab7bf to your computer and use it in GitHub Desktop.
Regular Expression pattern match
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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