Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Re: Global regex giving up too soon

by Wassercrats
on Jan 20, 2004 at 11:24 UTC ( #322558=note: print w/ replies, xml ) Need Help??


in reply to Re: Global regex giving up too soon
in thread Global regex giving up too soon

For the given example string, there's only one "href", so the /g is pointless as well.

I figured that was my problem. That's why I tried using /c, but I couldn't find a good description of how it worked. So basically, I guess there is no way to get /g to look over the entire regex, so I'll have to use while $& or establish that there's an href earlier so I don't have to use it in the regex.

Anyway, thanks for not telling me to use a module!


Comment on Re: Re: Global regex giving up too soon
Re: Global regex giving up too soon
by Abigail-II (Bishop) on Jan 20, 2004 at 11:28 UTC
    So basically, I guess there is no way to get /g to look over the entire regex,
    What do you mean by "looking over the entire regex"? /g means "match repeatedly (without overlap)".

    Abigail

      Well, does it make sense that there is a substitution made in more than one iteration of my loop, but if I use the regex alone, there are fewer (only one) substitutions made?
        Yes, of course. Consider:
        #!/usr/bin/perl use strict; use warnings; my $str = "1" x 5; $_ = $str; print "Single s///g:\n"; print "Before: [$_]; "; s/1(1+)/$1/g; print "After [$_]\n"; $_ = $str; print "Loop s///:\n"; while (1) { print "Before: [$_]; "; last unless s/1(1+)/$1/; print "After: [$_]\n"; } print "\n"; __END__ Single s///g: Before: [11111]; After [1111] Loop s///: Before: [11111]; After: [1111] Before: [1111]; After: [111] Before: [111]; After: [11] Before: [11]; After: [1] Before: [1];

        Abigail

Re: Re: Re: Global regex giving up too soon
by jdporter (Canon) on May 03, 2004 at 04:53 UTC

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2014-11-23 06:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (128 votes), past polls