in reply to Re^3: regex extraction for variable number of args
in thread regex extraction for variable number of args

Ok - it is beginning to sink in - so - it appears that there is no useful/meaningful way to combine non-capturing parens and repetition, unless your pattern starts at the beginning - in which case, you are better-off with the "/g" modifier . Or you are always better-off with the "/g" modifier.

So - is there a use case for non-capturing parens with repetition ?

             I hope life isn't a big joke, because I don't get it.
                   -SNL

  • Comment on Re^4: regex extraction for variable number of args

Replies are listed 'Best First'.
Re^5: regex extraction for variable number of args
by Corion (Patriarch) on Jul 22, 2012 at 07:15 UTC

    I can think of many uses for non-capturing parentheses with repetition. In fact, non-capturing parentheses with repetition are more sane than capturing parentheses with repetition, because the capturing parentheses will only keep the last match of the repetition. As an example a simple checker to check that a line matches a CSV-like format, using non-capturing parentheses and repetition:

    $line =~ /^(?:[^,]+|"[^"]+")(?:,(?:[^,]+|"[^"]+"))*$/

    That one matches one well-formed column, and then optionally a repetition of comma and more well-formed column.