basicly, we want to take a few characters off as possible, and count our spaces... also, we have to save the first part of the replacement (hence the ()'s), since we don't want to throw it away.$name =~ s/(.*?\s.*?\s.*?\s.*?)\s/$1\n/;
we should allow for multiple spaces in a row, since I think those should count as one:
You could also write the same thing here as:$name =~ s/(.*?\s+.*?\s+.*?\s+.*?)\s+/$1\n/;
and just repeat a section 3 times. A similar approach would be to replace the .*? parts with \S+ - I think this will be faster, as the regex engine will have less options on how ot match:$name =~ s/((?:.*?\s+){3}.*?)\s/$1\n/;
Hope that helps! See man perlre for lots more info!$name =~ s/((?:\S+\s+){3}\S+)/$1\n/;
-- Dan
In reply to Re: Need help with regex to replace 4th \s with \n in data line
by zigdon
in thread Need help with regex to replace 4th \s with \n in data line
by Popcorn Dave
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |