检查是否是 emoji 字符
Check if emoji character
我有一个 Java servlet,它接受来自移动设备的文本。在将其插入数据库之前,我需要检查每个字符并检查它是普通文本还是表情符号。我遇到的问题是如何检测字符是否为表情符号?
好的简单示例定义了私有字符串表情符号正则表达式。
private final String regex = "([\u20a0-\u32ff\ud83c\udc00-\ud83d\udeff\udbb9\udce5-\udbb9\udcee])";
带有测试句的变量
test = "josh stevens is the best "
您可以使用 Matcher
在测试字符串中查找与 regex
相匹配的任何组。
Matcher matchEmo = Pattern.compile(regex).matcher(test);
while (matchEmo.find()) {
System.out.println(matchEmo.group());
}
这将打印在字符串中匹配它们的表情符号。
希望这有帮助。
我有一个 Java servlet,它接受来自移动设备的文本。在将其插入数据库之前,我需要检查每个字符并检查它是普通文本还是表情符号。我遇到的问题是如何检测字符是否为表情符号?
好的简单示例定义了私有字符串表情符号正则表达式。
private final String regex = "([\u20a0-\u32ff\ud83c\udc00-\ud83d\udeff\udbb9\udce5-\udbb9\udcee])";
带有测试句的变量
test = "josh stevens is the best "
您可以使用 Matcher
在测试字符串中查找与 regex
相匹配的任何组。
Matcher matchEmo = Pattern.compile(regex).matcher(test);
while (matchEmo.find()) {
System.out.println(matchEmo.group());
}
这将打印在字符串中匹配它们的表情符号。 希望这有帮助。