Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: how to extract string by possible groupings?

by muba (Priest)
on Jun 02, 2014 at 15:42 UTC ( [id://1088275]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    $string = "foo bar";
    @match = $string =~ m/(f(oo)) (b(ar))/
    ...
    print "$match[1]\n";    # prints "oo"  (captured by /(oo)/
    print "$match[2]\n";    # prints "bar" (captured by /(b(ar))/
    print "$match[3]\n";    # prints "ar" (captured by  /(ar)/
    
  2. or download this
    use Data::Dumper;
    
    ...
    test1.cpp     0.00% of 21     0.00% of 16
    test2.c     None   16.53% of 484
    test3.h         0.00% of 138    None
    
  3. or download this
    [... snip ...]
    test1.cpp     0.00% of 21     0.00% of 16
    ...
              undef,
              undef
    [... snip ...]
    
  4. or download this
    /(.*\.(?:c|cpp|h))\s+/   # Use (?:...) to create a non-capturing group
    +.
    
  5. or download this
    # I always start my script with these two lines.
    # They prevent you from making various mistakes
    ...
    test1.cpp     0.00% of 21     0.00% of 16
    test2.c     None   16.53% of 484
    test3.h         0.00% of 138    None
    
  6. or download this
    test1.cpp     0.00% of 21     0.00% of 16
    Title:    test1.cpp
    ...
    Title:    test3.h
    Percent2: 0.00% of 138
    Percent3: None
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-26 05:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found