tags:

views:

80

answers:

2
A: 

Blind guessing, since I can't know for sure without the code and some test cases:

That regular expression only catches instances of [:)] and [;)] that are either surrounded by whitespace, or are at the beginning or end of a string. That's what (?:\s|^) and (?:\s|$) mean. It will not match Hello[:)]World, possibly by design. Is that the sort of case you're testing it on?

EDIT: Got it. Because of how the regular expression is written, by testing for spaces on either side, it includes those spaces in the match. Those matches can't overlap. If you were to separate them with two spaces, you would see intended behavior.

If you don't care about it not running up against words, your job with that regex is extremely simplified: escape the emoticons, then join them with |, to produce /\[\:\)\]|\[\;\)\]/.

This might be a better place to just use str_replace a few times, though.

Matchu
No, I tested with "Test [:)] [;)] Test" and that didn't work. Only the first [:)] is replaced, and not the other [;)]. I just edited my post above with the code.
van00
I would like to have Test.[:)] be replaced as well, though currently it isn't being.
van00
@van00: edited.
Matchu
Thank you! I just ended up using str_replace().
van00
+1  A: 

This (simplified) regular expression should replace every instance of [:)] and [;)] :

(?:\[[:;]\)\])
Clay Hinson