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

Re: Capturing all instances of a repeating sub-pattern in regex

by kennethk (Abbot)
on Nov 16, 2012 at 18:41 UTC ( #1004231=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
        $text =~ s/
              (.+?)            (?:\s*\n)+
          ((?: \d+ (?:\sPSI)? (?:\s*\n)+ ){4})
         /push @r, [ $1, $2 =~ m|\d+ (?:\sPSI)?|xg ]/esgx;
    
  2. or download this
        $text =~ s/
              (.+?)            (?:\s*\n)+
          (?: (\d+ (?:\sPSI)?) (?:\s*\n)+ )
    ...
          (?: (\d+ (?:\sPSI)?) (?:\s*\n)+ )
          (?: (\d+ (?:\sPSI)?) (?:\s*\n)+ )
         /push @r, [ $1, $2, $3, $4, $5 ]/esgx;
    
  3. or download this
        my $sub_re = qr/ (\d+ (?:\sPSI)?) (?:\s*\n)+ /x;
        $text =~ s/
              (.+?)            (?:\s*\n)+
    ...
          $sub_re
          $sub_re
         /push @r, [ $1, $2, $3, $4, $5 ]/esgx;
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1004231]
help
Chatterbox?
[thepkd]: Hey 1nickt sorry man. What
[GotToBTru]: a ref too far ;)
[thepkd]: Yes this is my first time in cb. Trying to work my way around.
[JohnCub]: "A ref too far" would make a good title for anyone's perl memoirs
[thepkd]: Anyways it works with $aohoaoh[0]->{'foo '}[0]->{'bar'}
[GotToBTru]: "I did it my $way"
[JohnCub]: I hope $way isn't a hashref. ;)

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (12)
As of 2016-12-06 13:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (105 votes). Check out past polls.