remove Accents using regex - Java java.util.regex

Java examples for java.util.regex:Match Unicode

Description

remove Accents using regex

Demo Code


//package com.java2s;
import java.text.Normalizer;
import java.text.Normalizer.Form;

public class Main {
    public static void main(String[] argv) {
        String text = "java2s.com";
        System.out.println(removeAccents(text));
    }//from   ww  w . j  ava  2  s.  co  m

    public static String removeAccents(String text) {
        return text == null ? null : Normalizer.normalize(text, Form.NFD)
                .replaceAll("\\p{InCombiningDiacriticalMarks}+", "");
    }
}

Related Tutorials