Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Regex help

by Eimi Metamorphoumai (Deacon)
on Jan 14, 2006 at 18:53 UTC ( #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
Node Status?
node history
Node Type: note [id://523207]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2020-10-23 12:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (238 votes). Check out past polls.

    Notices?