http://www.perlmonks.org?node_id=1005210


in reply to Re^5: Space between digits
in thread Space between digits

    s/ /   / if m/\d+\:\d+ \d+\/\d+\/\d+/;

And because substitution is already conditional upon a match, the operation can easily be further briefened (if that's a word) and also made more specific and at the same time more general or global:

>perl -wMstrict -le "my $string = '9 9 0:00 11/21/2012 12:34 01/23/2012 9 9'; print qq{'$string'}; ;; $string =~ s{ \d{1,2}:\d{2} \K [ ] (?= \d{2}/\d{2}/\d{2}) } { }xmsg; print qq{'$string'}; " '9 9 0:00 11/21/2012 12:34 01/23/2012 9 9' '9 9 0:00 11/21/2012 12:34 01/23/2012 9 9'

The stage is now set to factor out the definitions of time and date, etc., so they can easily be made more specific, perhaps ultimately being able to reject things like a 'time' of 99:99 or a 'date' of 98/76/5432, or accept a date in the form of either 01/23/2012 or 2012/01/23, etc.

>perl -wMstrict -le "my $string = '9 9 0:00 11/21/2012 12:34 01/23/2012 9 9'; print qq{'$string'}; ;; my $time = qr{ (?<! \d) \d{1,2} : \d{2} (?! \d) }xms; my $date = qr{ (?<! \d) \d{2} / \d{2} / \d{4} (?! \d) }xms; ;; $string =~ s{ $time \K [ ] (?= $date) }{ }xmsg; print qq{'$string'}; " '9 9 0:00 11/21/2012 12:34 01/23/2012 9 9' '9 9 0:00 11/21/2012 12:34 01/23/2012 9 9'