Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Regex for non-patterned input

by Lawliet (Curate)
on Aug 15, 2013 at 11:13 UTC ( #1049554=note: print w/replies, xml ) Need Help??

in reply to Regex for non-patterned input

Ah, so you cannot simply split on whitespace, because one of your columns has whitespace in it. Luckily, the data looks simple enough that we can get around that. For example, try the following (untested) regex:

for ( @wtodays ) { if (/^(\w+)\s+(\w+)\s+(\w+)\s+([\w\s]+)\s+(\w+)$/) { $table->addRow($1, $2, $3, $4, $5); } }

We individually capture each column. You can see that the regex for capturing the fourth column looks different than the others because of the whitespace it will contain. Specifically, instead of grabbing all the word-like characters, we grab all word-like and space-like characters, and then continue on our merry way to capturing the fifth column.

I hope this helps, and I hope you understand the logic behind it.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1049554]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2018-07-19 19:07 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (416 votes). Check out past polls.