thanos1983 has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,
I have spend so many hours and I still can not figure it out how to do it. I have a string that contains timestamps that I want to remove. As a second step I want to remove all the white space between the timestamp and the next "[" character. I have created a sample of code, but it is not even close to what I want to achieve:
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $initialStr = "[20150302 22:01:05] [1, 2, 3, 4] String0\n [20150302 + 22:01:05] [1, 2, 3, 4] String1\n [20150302 22:01:05] [1, 2, 3, 4] St +ring2\n [20150302 22:01:05] [1, 2, 3, 4] String3\n [20150302 22:01:05 +] [1, 2, 3, 4] String4\n [20150302 22:01:05] [1, 2, 3, 4] String5\n [ +20150302 22:01:05] [1, 2, 3, 4] String6\n [20150302 22:01:05] [1, 2, +3, 4] String7\n"; my @matches = ( $initialStr =~ /\d+:\d+:\d+/ ); print Dumper \@matches; __END__ $VAR1 = [ 1 ];
I was thinking of having initialy a regex to remove the timestamps, and the next line character. And at the end another regex to remove the remaining white space until the first occurence of "[" this character for each substring. Something like that I had in my mind. I have not used regex over a year and I am really bad at it. Does anyone has an idea how to do that?
Sample of desired output:
$VAR1 = [ [1, 2, 3, 4] String0, [1, 2, 3, 4] String1, [1, 2, 3, 4] String2, [1, 2, 3, 4] String3, [1, 2, 3, 4] String4, [1, 2, 3, 4] String5, [1, 2, 3, 4] String6, [1, 2, 3, 4] String7 ];
|
|---|