This question already has an answer here:
- Backslash in java 4 answers
- Java - regular expression to match a backslash followed by a quote 3 answers
I am trying to match a emoji code in json from a string so i can replace it with html code. This is how the string looks like "\uD83D\uDE42".
This is my regex expression that i wrote "\u[0-9]0-9(\u([a-z]|[A-Z])([0-9]|[a-z])([a-z]|[A-Z]|[0-9]))?"
I tested this expression in an online tool on multiple patterns it worked but in android code it does not detect the pattern.
Moreover the testing string could be like this \uD83D\uDE42" or \ud83d\ude42" or "\u270a" or "\ud83d\udcaa" or even this "\ud83d\udc4a". On an online tool (https://regexr.com/).
This is the code i wrote
String stringToSearch = "Four score and seven years ago our \uD83D\uDE42 fathers ...";
Pattern p = Pattern.compile("\\[u][A-Z][0-9][0-9][A-Z]\\[u][A-Z][A-Z][0-9][0-9]"); // the pattern to search for
Matcher m = p.matcher(stringToSearch);
// now try to find at least one match
if (m.find())
System.out.println(stringToSearch+"\nFound a match");
else
System.out.println(stringToSearch+"\nDid not find a match");
Aucun commentaire:
Enregistrer un commentaire