Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Arbitrary number of captures in a regular expression

by Sidhekin (Priest)
on Sep 23, 2007 at 20:59 UTC ( [id://640613]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my (@match) = $str =~ /(?:^foo |(?<!^)\G)m (\d+) (?=(?:m \d+ )*bar)/g;
    
  2. or download this
    my @test = ( 'foo m 1 m 2 m 3 m 4 bar',
                 'foo m 2 m 4 m 7 bar',
    ...
      local $" = ', ';
      print "'$str' => (@match)\n";
    }
    
  3. or download this
    'foo m 1 m 2 m 3 m 4 bar' => (1, 2, 3, 4)
    'foo m 2 m 4 m 7 bar' => (2, 4, 7)
    ...
    'foo m 1 c 2 bar' => ()
    'foo m 1 bar m 2' => (1)
    'foo m 1 m 5 m 7' => ()
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-04-19 02:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found