Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Pattern Matching request

by zejames (Hermit)
on Dec 15, 2004 at 08:41 UTC ( #414960=note: print w/replies, xml ) Need Help??

in reply to Pattern Matching request

There are somes things that aren't clear : does the number belong to data, or is it another information ?

Here, I've considered that numbers before the STRUCT keyword and data are not the same. Plus I've taken into account the fact that data may contains numbers. What make these numbers different is that they do not precede a STRUCT keyword.

To sum up the proposed solution to your problem : match everything and then remove what you are not interested in.

# Text wrapped to fit in the screen my $text = "0011222STRUCTdata..........6ab.." . "02121STRUCTdata.........." . "021232STRUCTdata......" . "02342STRUCTdata......"; my @matches = $text =~ m/(\d+) # First match some numbers STRUCT # Then the STRUCT keyword (.+?) # Then the data, that have to # be followed by (?= # (look-ahead assertion) (?:\d+STRUCT # - numbers and 'STRUCT' | # or $ # - end of line ) )/xg; # Then remove the first two matches that is first numbers and # first data @matches = splice @matches, 2; { local $, = ","; print @matches, "\n"; }

The look ahead trick helps to easily manage numbers in the data text.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2020-10-19 15:42 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (205 votes). Check out past polls.