in reply to Re^6: Splitting compound (concatenated) words )
in thread Splitting compound (concatenated) words )
In the same way that this matches:
$s = 'fred';; print for $s =~ /^(.)?(.)?(.)?(.)?(.)?(.)?$/;; f r e d Use of uninitialized value $_ in print at (eval 10) line 1, <STDIN> li +ne 2. Use of uninitialized value $_ in print at (eval 10) line 1, <STDIN> li +ne 2.
Although there are 6 capture groups, and only 4 characters, the capture groups are optional because of the trailing '?' ((.)?).
So long as the regex has more capture groups than the string contains matches, the regex will match as many as are available, and the remaining capture groups will (optionally) "match" nothing, and so return undefs.
Does that clarify things?
|
|---|