I've added emojis to my Android application and I've been using Regex, in Java, so the codes assigned to them will match the regular expression (which contains a pair of delimiters to be used with), making the characters show up as images.
Some emoji codes are, for example, sad
, happy
, smile
.
So far, it's been like this:
Delimiters:
(
and)
Regular expression:
\\(([.[^\\(\\)]]+)\\)
Example of emoji codes matched:
(sad)
,(happy)
,(smile)
.
I've noticed, tho, that for some new emojis that I added, it would be more practical for the user to type their codes using another pair of delimiters, like the letter z
and ,
. Then, the second case would be like this:
Delimiters:
z
and,
Regular expression:
z([.[^z\\,]]+)\\,
Example of emoji codes matched:
zsad,
,zhappy,
,zsmile,
.
What I want, then, is to merge both of these two regular expressions, so the user can type the emoji code using either of the two pair of delimiters, whichever he or she prefers, and it will be matched. For example, the sad emoji would be matched and it would show up as an image everytime it's written as either (sad)
orzsad,
, like in:
Hi. (sad) I've got bad news. zsad,
Hey... (sad)
Okay. Bye. zsad,
I've tried using alternation operator and lookarounds with no success. In the following two regular expressions, I only had matches to what is left of the |
alternator (and I want matches for both left and right sides, of course):
\\(([.[^\\(\\)]]+)\\)|z([.[^z\\,]]+)\\,
z([.[^z\\,]]+)\\,|\\(([.[^\\(\\)]]+)\\)
And in the following regular expressions, I had no matches at all:
(\\(([.[^\\(\\)]]+)\\)|z([.[^z\\,]]+)\\,)
, (\\(([.[^\\(\\)]]+)\\))|(z([.[^z\\,]]+)\\,)
(z([.[^z\\,]]+)\\,|\\(([.[^\\(\\)]]+)\\))
, (z([.[^z\\,]]+)\\,)|(\\(([.[^\\(\\)]]+)\\))
\\(|z([.[^\\(\\z\\,)]]+)\\)|\\,
, (\\(|z)([.[^\\(\\z\\,)]]+)(\\)|\\,)
(\\()|(z)([.[^\\(\\z\\,)]]+)(\\))|(\\,)
(?=\\(([.[^\\(\\)]]+)\\))(?=z([.[^z\\,]]+)\\,)
, (?=.*\\(([.[^\\(\\)]]+)\\))(?=.*z([.[^z\\,]]+)\\,)
Sorry for the gigantic text, I only wanted to give as much details as possible. Does anyone know what I am doing or writing wrong, and what regular expression I can use so it matches both zemojicode,
and (emojicode)
? Your help will be very much appreciated.