Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Regex matching

by Aristotle (Chancellor)
on Jul 03, 2002 at 13:24 UTC ( [id://179150]=note: print w/replies, xml ) Need Help??


in reply to Regex matching

But this only returns the penultimate charcter block before the newline

The last block is followed by a newline, not a blank, while in your regex there is a space trailing the block, so it does not match. Next problem, it only returns a single block because you match the entire string at once, but capture into always the same parens. So after one single iteration you have "eaten" the entire string, but you only get the last paren content.

Update: Checking for a UFOFH at the start of the line then splitting on blanks as suggested is a probably the easiest and most robust solution, but you can do it with just regexen:
$_ = q(UFOFH 33603 01231 /0000 0024/ 1024/ 2025/ 3027/ 4030/ 5025/ 602 +8/ 7060/ 8081/ 9098/ 0110/ 1107/ 2106/ 3102/ 4080/ 5065/ 6057/); my @block; if(/^UFOFH/gi) { # NB: /g is necessary for the following \G to work my @matches = m#\G\s([/\d]{5})#g; @block = splice @matches, 0, 27 if @matches >= 4; } print "@block\n";

The \G is an anchor kind of like ^, except it does not match at the beginning of the string, but at the point where the previous /g match ended. As you see, it is slightly complicated to do this without split..

Update: I have a ways yet to go, obviously. The above solution bugged me, just slightly but it did. It took a day until I realized how to do it well - or more like, slap my forehead and say "D'oh".. This is the real thing (until further notice..):

my @matches = m#(?:^UFOFH|\G)\s([/\d]{5})#g; my @block = splice @matches, 0, 27 if @matches >= 4; print "@block\n";
____________
Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Re: Regex matching
by Anonymous Monk on Jul 03, 2002 at 13:35 UTC

    Thanks everyone for all your help. I have now got a working expression! And it is slightly neater than the previous effort...

    The data structures are among email headers, which sometimes contain bits of the data. Unfortuantly not everyone sticks to quite the same data format, sometimes those /'s can be numbers, and the 'UFOFH' comes in a mixed case.

    Thanks again

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-03-28 14:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found