Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (10)
As of 2019-05-27 11:44 GMT
Find Nodes?
    Voting Booth?
    Do you enjoy 3D movies?

    Results (156 votes). Check out past polls.