Removing accents and diacritics from given text . - Java Regular Expressions

Java examples for Regular Expressions:Pattern

Description

Removing accents and diacritics from given text .

Demo Code


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

public class Main {

    /**//from w  w  w  .ja  va2 s  .  co  m
     * Removing accents and diacritics from given {@code text}.
     *
     * @param text
     * @return given {@code text} without accents and diacritics
     */
    public static String removeAccents(String text) {
        if (text == null) {
            return null;
        }
        text = Normalizer.normalize(text, Normalizer.Form.NFD);
        return text.replaceAll("\\p{InCombiningDiacriticalMarks}+", "");
    }
}

Related Tutorials