Skip to content
Advertisement

Extract specific data from string using Regex (PHP)

My objective is to check if the message have emojis or not , if yes i am going to convert them. I am having a problem to find out how many emojis are in the string.

Example :

JavaScript
  • the objective here is to get the :+1: ( all of them ) but i tried two pattern and i keep getting only 1 match.

    JavaScript

The Rest of the code
after getting the matches i am doing this :

JavaScript

i would appreciate any help or suggestions , Thanks.

Advertisement

Answer

I updated your expression a little bit:

JavaScript
  • The : is now escaped, otherwise it could be treated as special character.
  • Replaced the * by +, this way you won’t match two consecutive :: but require at least one charcter in-between.
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement