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 ];
Seeking for Perl wisdom...on the process of learning...not there...yet!

In reply to regex remove blank/whitespace until first occurrence of specific character "[" by thanos1983

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.