de-accents a string via Regex - Java java.util.regex

Java examples for java.util.regex:Match Unicode

Description

de-accents a string via Regex

Demo Code


//package com.java2s;
import java.text.Normalizer;
import java.util.regex.Pattern;

public class Main {
    public static void main(String[] argv) {
        String description = "java2s.com";
        System.out.println(deaccent(description));
    }// w  ww  . jav a2s  .c o m

    /**
     * de-accents a string
     * @param description
     * @return
     */
    public static String deaccent(String description) {

        String nfdNormalizedString = Normalizer.normalize(description,
                Normalizer.Form.NFD);
        Pattern pattern = Pattern
                .compile("\\p{InCombiningDiacriticalMarks}+");
        return pattern.matcher(nfdNormalizedString).replaceAll("");

    }
}

Related Tutorials