1. 程式人生 > >Java清除標點符號的正則表示式

Java清除標點符號的正則表示式

               

轉載請註明:http://www.pmjava.com/?thread-62961-1.html

[java] view plain copy print?
  1. package com.test;    
  2. publicclass StringTest {    
  3.      publicstaticvoid main(String... args) {       
  4.            String str = "!!!??!!!!%*)%¥!KTV去符號標號!!當然。!!..**半形";       
  5.            // System.out.println(str);     
  6.             System.out.println(str.replaceAll("//p{Punct}"
    ""));       
  7.             System.out.println(str.replaceAll("//pP"""));       
  8.            System.out.println(str.replaceAll("//p{P}"""));       
  9.           }       
  10. }    
package com.test;   public class StringTest {       public static void main(String... args) {                String str = "!!!??!!!!%*)%¥!KTV去符號標號!!當然。!!..**半形";                // System.out.println(str);                 System.out.println(str.replaceAll("//p{Punct}", ""));                 System.out.println(str.replaceAll("//pP", ""));                System.out.println(str.replaceAll("//p{P}", ""));               }       }