Expressions régulières: Trouver et remplacer les ASCII non alphabet ou chiffre

Author:

 java
Download

 
import java.util.regex.Matcher;
import java.util.regex.Pattern;
 
public class RegexPunct
 {
  public static void main(String[] argv) throws Exception
  	{
 
    String str = "Bienvenu sur Mesexemples.com copyright 2010-2012";
 
    // Remplcer tous les caractères qui ne sont pas alphabétique et chiffre
    System.out.println (str.replaceAll("[\p{Print}&&\P{Alnum}]","-"));
 
    if("b".matches("[\p{Print}&&\P{Alnum}]"))
    	System.out.println ("Le String correspond au pattern");
 
    if(!"p ".matches("[\p{Print}&&\P{Alnum}]"))
    	System.out.println ("Le String ne correspond pas au pattern");
  }
}

Cet article Expressions régulières: Trouver et remplacer les ASCII non alphabet ou chiffre est apparu en premier sur .