I am trying to parse a regular expression pattern in Ruby. The pattern is similar to
<number>? <comma>? <number>? <term>*
Where:
number is one or more digitscomma ","termhas the form [.*]or[^.*]
And I'm trying to fix numbers and all terms. To clarify, here are a few examples of valid patterns:
5,50[foo,bar]
5,[foo][^apples]
10,100[baseball][^basketball][^golf]
,55[coke][pepsi][^drpepper][somethingElse]
Firstly, I would like to seize 5, 50and [foo,bar]
in the second case I would like to capture 5, [foo]and [^apples]etc.
The sample I came across is:
/(\d+)?,?(\d+)?(\[\^?[^\]]+\])+/
but this only matches the numbers and the last term. If I delete +at the end, then it will only match the first member.
source
share