匹配所有表情的正则表达式

    

public static void main(String[] args) { String input = " 提前1天预约 ??21111211211 ?? 2????"; // 输入包含Emoji表情符号的字符串 String emojiPattern = "(?:[uD83CuDF00-uD83DuDDFF]|[uD83EuDD00-uD83EuDDFF]|[uD83DuDE00-uD83DuDE4F]|[uD83DuDE80-uD83DuDEFF]|[u2600-u26FF]uFE0F?|[u2700-u27BF]uFE0F?|u24C2uFE0F?|[uD83CuDDE6-uD83CuDDFF]{1,2}|[uD83CuDD70uD83CuDD71uD83CuDD7EuD83CuDD7FuD83CuDD8EuD83CuDD91-uD83CuDD9A]uFE0F?|[u0023u002Au0030-u0039]uFE0F?u20E3|[u2194-u2199u21A9-u21AA]uFE0F?|[u2B05-u2B07u2B1Bu2B1Cu2B50u2B55]uFE0F?|[u2934u2935]uFE0F?|[u3030u303D]uFE0F?|[u3297u3299]uFE0F?|[uD83CuDE01uD83CuDE02uD83CuDE1AuD83CuDE2FuD83CuDE32-uD83CuDE3AuD83CuDE50uD83CuDE51]uFE0F?|[u203Cu2049]uFE0F?|[u25AAu25ABu25B6u25C0u25FB-u25FE]uFE0F?|[u00A9u00AE]uFE0F?|[u2122u2139]uFE0F?|uD83CuDC04uFE0F?|uD83CuDCCFuFE0F?|[u231Au231Bu2328u23CFu23E9-u23F3u23F8-u23FA]uFE0F?)"; Pattern pattern = Pattern.compile(emojiPattern); Matcher matcher = pattern.matcher(input); StringBuilder sb= new StringBuilder(); while (matcher.find()) { String emoji = matcher.group(); System.out.println("Found emoji: ?" + emoji); System.out.println(StringEscapeUtils.escapeJava(emoji)); // 打印结果 input= input.replace(emoji, StringEscapeUtils.escapeJava(emoji)); } System.out.println(input); // 打印结果 }