Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: regexp: ?<=

by MCS (Monk)
on Feb 16, 2006 at 14:44 UTC ( [id://530662]=note: print w/replies, xml ) Need Help??


in reply to regexp: ?<=

As others have mentioned, /(?<=\t)\w+/ does not include the tab in $& which contains the text that the regular expression matched. Perhaps some code might make it a little clearer:

#!/usr/bin/perl use strict; my $string = "Testing \tthis regex"; print $string, "\n"; $string =~ /(?<=\t)\w+/; my $string1 = $&; $string =~ /\t\w+/; my $string2 = $&; print "/(?<=\\t)\w+/:\n" . $string1 . "\n"; print "/\\t\w+/:\n" . $string2 . "\n";

This is mostly useful for substitutions but hopefully my code makes it a little clearer as to what is going on. The output is as follows:

Testing this regex /(?<=\t)w+/: this /\tw+/: this

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-25 12:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found