Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP REGEX: Problem with Smiley `:)` and `:))`

Tags:

regex

php

What I want


Hi! I want to replace :) to smile.png and :)) to laugh.png.

The problem


The script finds :) inside :)) so laugh.png is not shown, only smile.png+)

This is what I have tried so far for :)):


preg_replace("/:)+(?!))/i",$image, $string))

Some other regexes what I tried:

"/\:\)+(?=\))/i"

"/\:+(?=\)\))/i"

But nothing want's to work what I tried yet.

like image 571
Adam Halasz Avatar asked Mar 23 '26 10:03

Adam Halasz


1 Answers

For :) – (:\)(?!\)))

Then

For :)) – (:\)\))

like image 195
hookedonwinter Avatar answered Mar 26 '26 00:03

hookedonwinter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!