Jan 18, 2010, 8:10 PM
Post #2 of 2
Re: [mhassan] String: Doesn't want to split at 4th occurrence
[In reply to]
my @pieces = split /\s(?!-)/, $str;
The (?! ) part is a 'zero width negative lookahead'. It matches any character but the one listed--in this case a minus sign. But very importantly, once the match is found, it is not treated as part of the result match. In other words, the regex above will look for a space followed by anything but a minus sign and then split on only the space.
Of course, you have given NO information about the pattern of your data. Whether that will work for all your data is impossible to tell. One example is meaningless.
(This post was edited by 7stud on Jan 18, 2010, 10:17 PM)