Home >Backend Development >Golang >How to Replace Emoji Characters in a Java String Using Regular Expressions?

How to Replace Emoji Characters in a Java String Using Regular Expressions?

Linda Hamilton
Linda HamiltonOriginal
2024-11-25 20:35:191020browse

How to Replace Emoji Characters in a Java String Using Regular Expressions?

Use a regex to match emoji characters in a string. For example:

import java.util.regex.Pattern;

public class ReplaceEmojis {

    public static void main(String[] args) {
        String text = "That's a nice joke ??? ?";
        String replaced = text.replaceAll("[\p{Extended_Pictographic}]", "[e]");
        System.out.println(replaced); // That's a nice joke [e][e][e] [e]
    }
}

The above is the detailed content of How to Replace Emoji Characters in a Java String Using Regular Expressions?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn