in reply to Re: Quick regex substitution question
in thread Quick regex substitution question

For the sake of people in the future reading this thread, you can use look ahead/behind to split() something, and retain the thing you split on.

The following split() splits on either whitespace or nothing with a '.' before it. The whitespace, if present, is thrown away, but the dot is retained within each split() element.

#!/usr/bin/perl my $string = "I have. In my string.Replace all but last one."; @parts = split(/(?<=\.)\s*/, $string); print "$_\n" for @parts; __END__ ./split.pl I have. In my string. Replace all but last one.

-stevieb