From what I get from comments, some of this may or may not help -
To validate a string contains 1 or more emoji :
# ^(?=[\S\s]*(?:\ud83d[\ude00-\ude4f]))
^
(?=
[\S\s]*
(?: \ud83d [\ude00-\ude4f] )
)
To remove only emoji, leaving the rest (global) :
Find: (?:\ud83d[\ude00-\ude4f])*((?:(?!\ud83d[\ude00-\ude4f])[\S\s])+)(?:\ud83d[\ude00-\ude4f])*
Replace: $1
(?: \ud83d [\ude00-\ude4f] )*
( # (1 start)
(?:
(?! \ud83d [\ude00-\ude4f] )
[\S\s]
)+
) # (1 end)
(?: \ud83d [\ude00-\ude4f] )*
To remove everything but emoji (global) :
Find: ((?:\ud83d[\ude00-\ude4f])*)(?:(?!\ud83d[\ude00-\ude4f])[\S\s])+((?:\ud83d[\ude00-\ude4f])*)
Replace: $1$2
( # (1 start)
(?: \ud83d [\ude00-\ude4f] )*
) # (1 end)
(?:
(?! \ud83d [\ude00-\ude4f] )
[\S\s]
)+
( # (2 start)
(?: \ud83d [\ude00-\ude4f] )*
) # (2 end)
edit: To use different emoji utf16 ranges do this
Different high surrogates:
(?:
High_surrogate_A [Low_surrogate_start_A-Low_surrogate_end_A]
| High_surrogate_B [Low_surrogate_start_B-Low_surrogate_end_B]
| High_surrogate_C [Low_surrogate_start_C-Low_surrogate_end_C]
)
or, same high surrogate, different low surrogate ranges:
(?:
High_surrogate [Low_surrogate_start1-Low_surrogate_end1Low_surrogate_start2-Low_surrogate_end2]
)
or, mix:
(?:
High_surrogate_A [Low_surrogate_startA1-Low_surrogate_endA1Low_surrogate_startA2-Low_surrogate_endA2]
| High_surrogate_B [Low_surrogate_start_B-Low_surrogate_end_B]
)
Where you see:
(?: \ud83d [\ude00-\ude4f] )*
substitue one of the above in placeholder HERE
HERE*
Where you see:
(?! \ud83d [\ude00-\ude4f] )
substitue one of the above in placeholder HERE
(?! HERE )
Note- you can add a High-surrogate range as well, however all the high surrogates must share the same low-surrogate(s) range.
"I'm trying multiple regex expressions"- and have posted none? what does an emoji look like in a javascript string? – Jaromanda X Aug 10 '15 at 11:29tags.replace(/^[\u1f600-\u1f64f]/g, 'X');, which instead of removing the characters should change them for an 'X'. – tontonton Aug 10 '15 at 11:32.replace(/\ud83d[\ude00-\ude4f]/g, '')to remove all emojis, and then counts.length - s_new.length? – Wiktor Stribiżew Aug 10 '15 at 11:37