in reply to Re: Re: Re: Re: In need of a stupid regex trick
in thread In need of a stupid regex trick
Update: rewrote following paragraph for clarity.use Data::Dumper; $Data::Dumper::Terse = 1; print Dumper $_ for split /"([^"]*)"|\s+/, 'this "is" an "example"'; __END__ 'this' undef '' 'is' '' undef 'an' undef '' 'example'
The split splits the string 'this "is" an "example"' up everywhere there is a quoted string or repeated whitespace. This yields the substrings "this", "", "", "an", and "". Because there was one set of capturing parentheses in the split pattern, there will be one extra value returned for each split (this is a feature that allows you to split on several delimiters and see which delimiter was used). These extra values are undef, "is", undef, undef, and "example". Where the split was on whitespace, the value is undef because the capturing parentheses were not actually used in the match. Where the split was on a quoted string, the value is what was in the quotes.
|
|---|