I usually like the problems of regular expressions, and even better is their solution.
But it seems that I have a case that I cannot understand.
I have a string of values separated by a semicolon, such as a CSV string, which might look like this: 123-234;FOO-456;45-67;FOO-FOO;890;FOO-123;11-22;123;123;44-55;098-567;890;123-FOO;
On this line, I would like to match all integers and integer ranges to extract them later. It is possible that only one value (without a semi-colony).
After a great search, I managed to write this expression:
(?:^|;)(?<range>\d+-\d+)(?:$|;)|(?:^|;)(?<integer>\d+)(?:$|;)
Used test lines:
123123-234;FOO-456;45-67;FOO-FOO;890;FOO-123;11-22;123;123;44-55;098-567;890;123-FOO;123-456123-FOOFOO-123FOO-FOO
Lines 1 and 3 match correctly, but lines 4,5 6 do not.
In line 2, only one of the two values is correctly matched.
Here is a link to regex101.com that illustrates this: https://regex101.com/r/zA7uI9/5
I will also need to select integers and ranges separately (in different groups).
Note. I found a question that could help me and tried my answer (adapting it), but that didn't work. Regular expression to match numbers and number ranges
Do you have any ideas on what I am missing?
The language that will "use" this regular expression is C #, but I don’t know if this is useful information for my problem.
added by barlop
Below are matches to the current regex as shown at this link regex101.com
and for this test line it is 123-234;FOO-456;45-67;FOO-FOO;890;FOO-123;11-22;123;123;44-55;098-567;89
123-234 45-67 890 11-22 123 098-567
therefore its regular expression seems to miss one of the 123s, and 44-45 and 89 at the end.