Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Backref in a regex quantifier

by webfiend (Vicar)
on Jul 09, 2007 at 18:10 UTC ( #625675=note: print w/replies, xml ) Need Help??


in reply to Re: Backref in a regex quantifier
in thread Backref in a regex quantifier

Here's a marginally more clever version of your solution, which relies on the placeholder capabilities of a /g search. I mention it because I think it's a tiny bit more readable than the version you wrote. But ... you know ... personal preference and all that.

use strict; use warnings; my $test_string = "3 xyz"; # Start a global search # It looks like the expected pattern includes a space. Let's put it he +re. if ( $test_string =~ m/^(\d+) /g ) { my $length = $1; # Pick up the search where our first match left off. if ( $test_string =~ m/\G(.{$length})/ ) { my $result = $1; # Do stuff with $result ... } }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (12)
As of 2019-07-15 17:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?