Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: regexp bug

by thelenm (Vicar)
on Aug 27, 2002 at 17:10 UTC ( [id://193213]=note: print w/replies, xml ) Need Help??


in reply to regexp bug

As hotshot said, giving examples of how it's failing will be very helpful. Please give some examples of input you're giving it and output you expect.

It's not clear what $count is supposed to be, but it will actually be either 0 or 1 depending on whether the pattern matches $_. If you want a true count of the number of matches, you should do something like this instead:

$count = () = /\b\Q$query\E\b/ig;
I put the \Q and \E in there even though "foo" doesn't contain any special regex characters, because it guards against accidents if you search on something besides "foo" later. And you're correct to use /i to do a case-insensitive match.

-- Mike

--
just,my${.02}

Log In?
Username:
Password:

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

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

    No recent polls found