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

Re: Regex Question in Perl

by ikegami (Patriarch)
on Dec 22, 2010 at 18:29 UTC ( [id://878627]=note: print w/replies, xml ) Need Help??


in reply to Regex Question in Perl

The "?" in ".*?" makes ".*" matches as few characters as possible. Get rid of it.

Furthermore, the "g" in if (/.../g) makes no sense conceptually (check if there's a match, then check again to be sure?) or in practice (it has weird side effects). Get rid of it.

I dislike using global variables for no reason, so I'd write it

my $page2 = "Account number 12345678"; if ( my ($acct) = $page2 =~ /Account number (.*)/ ) { print "acct = $acct\n"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://878627]
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-26 00:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found