Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Regex help

by Eimi Metamorphoumai (Deacon)
on Jan 14, 2006 at 18:53 UTC ( [id://523207]=note: print w/replies, xml ) Need Help??


in reply to Regex help

The problem is that \b marks a "word boundary", that is, a place where one side must be a a word character (alphanumeric or _) and the other side isn't a word character. If the text in $symbol begins and ends with word characters, then it does what you want. But if the text in $symbol is, say, a comma, which isn't a word character, then your test is ensuring that it's surrounded on both sides by word characters. So what you want is not to assert a boundary, but rather that $symbol not be preceded by or followed by wordchars.
if ($sentence =~ /(?<!\w)$symbol(?!\w)/){ # do something }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-26 03:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found