Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

RegExps, Prematch and Postmatch without efficiency penalty

by davido (Cardinal)
on Sep 14, 2003 at 08:23 UTC ( [id://291363]=perlmeditation: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    sub prematch {
        return unpack "a$-[0]", $_[0];
    ...
        my $len = $+[0] - $-[0];
        unpack "x$-[0] a$len", $_[0];
    }
    
  2. or download this
    use strict;
    use warnings;
    ...
        print postmatch($string), "\n";
        print match($string), "\n";
    }
    
  3. or download this
    my ($pre, $match, $post) = split /\b(word)\b/, $string, 2;
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://291363]
Approved by PodMaster
Front-paged by IlyaM
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-20 15:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found