regex - RegExp in PHP not working as expected -


i've got problem , don't know how fix it. wan't parse emoticons of comments , i'm trying regexp not getting anything:

tried expression:

(?<=\s|^)[<:-}]+(?=\s|$)

and got blank message, showing. tried @ http://regexr.com/ , throws error in lookbehind part.

then found one:

~\b[<:-}]+\b~

and it's not working (but @ least shows message without converting emojis image , adding dot before last letter: x.d ^_.^ ...)

my code this:

$smiles = array(         'xd'    => 'laugh.png',         '>:)'   => 'laugh.png',         'x('    => 'angry.png',         ':(('   => 'cry.png',         ':*'    => 'kiss.png',         ':))'   => 'laugh.png',         ':d'    => 'laugh.png',         ':-d'   => 'laugh.png',         ':x'    => 'love.png',         '<3'    => 'love.png',         '(:|'   => 'sleepy.png',         ':)'    => 'smile.png',         ':-)'   => 'smile.png',         ':('    => 'sad.png',         ':-('   => 'sad.png',         ';)'    => 'wink.png',         ';-)'   => 'wink.png',         '^_^'   => 'wink.png',         '^^'    => 'wink.png',     );        if($this->smiles) {          foreach($smiles $icon=>$image) {               $icon = preg_quote($icon);               $parsedmessage = preg_replace("~\b".$icon."\b~",$image,$parsedmessage);          }     } 

any idea ? :s want parse them , avoiding parse when links example or things that.

greetings!

there 2 ( 1.5 ) issues:

  • (minor/spurious) hyphen - in test regexp , several of $smiles keys marks character range,which may not want;

  • (severe) preg_quote($icon) escapes characters special semantics in regex not add brackets , repetition operator of character class.


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -