Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: regex remove blank/whitespace until first occurrence of specific character "["

by choroba (Cardinal)
on Mar 02, 2015 at 21:56 UTC ( [id://1118493]=note: print w/replies, xml ) Need Help??


in reply to regex remove blank/whitespace until first occurrence of specific character "["

Data::Dumper can't produce the output you desire. Behold:
Bareword found where operator expected at -e line 3, near "] String0" (Missing operator before String0?) Bareword found where operator expected at -e line 4, near "] String1" (Missing operator before String1?) Bareword found where operator expected at -e line 5, near "] String2" (Missing operator before String2?) Bareword found where operator expected at -e line 6, near "] String3" (Missing operator before String3?) Bareword found where operator expected at -e line 7, near "] String4" (Missing operator before String4?) Bareword found where operator expected at -e line 8, near "] String5" (Missing operator before String5?) Bareword found where operator expected at -e line 9, near "] String6" (Missing operator before String6?) Bareword found where operator expected at -e line 10, near "] String7" (Missing operator before String7?) syntax error at -e line 3, near "] String0" Execution of -e aborted due to compilation errors.

To get all the matches from the m// operator, you need list context (which you already have), but also the /g option:

my @matches = $initialStr =~ /\d+:\d+:\d+/g;

Or, to get closer to your desired output:

my @matches = $initialStr =~ /\[ .*? \] \s* ( \[ .*? \] .* )/gx;
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: regex remove blank/whitespace until first occurrence of specific character "["
by thanos1983 (Parson) on Mar 03, 2015 at 09:10 UTC

    Hello choroba,

    Thank you for your time and effort answering my question. You are absolutely right it works perfect. I have so many things to learn. :D

    Seeking for Perl wisdom...on the process of learning...not there...yet!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1118493]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-19 19:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found