Do word boundaries work on symbol characters?
Posted
by
Shawn31313
on Stack Overflow
See other posts from Stack Overflow
or by Shawn31313
Published on 2012-06-11T16:20:47Z
Indexed on
2012/06/11
16:40 UTC
Read the original article
Hit count: 186
I'm trying to implement word boundaries in my emoticons feature for a chat. But for some reason I can't seem to get the word boundaries to work. I am new to regex.
So when I do:
var reg = /\b\Hi\b/gi;
var str = 'HiHiHi Hi HiHiHi Hi';
alert(str.replace(reg, ''));
This happens: Jsfiddle
It actually works fine, and does remove those 2 Hi's that are standing alone.
But when I change the reg to an escaped smiley and then change the string:
var reg = /\b\:\)\b/gi;
var str = 'HiHi:) :) HiHiHi :)';
alert(str.replace(reg, ''));
This happens: Jsfiddle
It just doesn't work. The string stays the same. Is it that word boundaries can't be used on symbols? If so, how does Facebook do it on their chats?
© Stack Overflow or respective owner