Reputation: 2859
I would like to find a number separated into 3 parts with 2 hyphens. Each part does not have a set number of figures so for example "123-12-12222" , "1-2303-11" "45456874-1-258" are all good. Any suggestions for a RegExp pattern? Thanks in advance.
Upvotes: 0
Views: 3986
Reputation: 350
line = "123-12-12222"
for ex.
match = Regex.Match(line, @"(\d+)-(\d+)-(\d+)",RegexOptions.IgnorePatternWhitespace);
the parenthese are used to grab the actual digits between the hyphens so you can reference them as such
a=match.Groups[0].Value;
b=match.Groups[1].Value;
c=match.Groups[2].Value;
Upvotes: 0
Reputation: 4795
Seems like this is fine for you:
\d+-\d+-\d+
3 sequences of 0-many digits, separated by -
s
RegExr Example matching the numbers in your post.
Upvotes: 3