[Solved] How to split a string and add new line before date


It’s not very good form to bring just a requirement to Stack Overflow without obviously having tried to solve the problem yourself. Without any code there is nothing to “help” with, and I hope you’ll at least make an effort in the future

Assuming there is always some whitespace before each date, this will work for you

use strict;
use warnings 'all';
use feature 'say';

my $string = '4/25/2011 11:34:07 AM [test] >> Need to change.  5/16/2011 10:44:45 AM [test] >> Nothing to change yet. Need to review information.  5/23/2011 11:13:39 AM [test] >> Working on it.';

$string =~ s|\s+(?=\d{1,2}/\d{1,2}/\d{4})|\n|g;

say $string;

output

4/25/2011 11:34:07 AM [test] >> Need to change.
5/16/2011 10:44:45 AM [test] >> Nothing to change yet. Need to review information.
5/23/2011 11:13:39 AM [test] >> Working on it.

3

solved How to split a string and add new line before date