javaRegex

來源:互聯網
上載者:User

標籤:blank   space   羅馬   tar   pac   java正則   dig   replace   start   

參考http://blog.csdn.net/telnetor/article/details/6041323

String str = ",.!,,D_NAME。!;‘’”“**dfs  #$%^&()-+1431221\"\"中           國123漢字かどうかのjavaを決定";str = str.replaceAll("[\\pP\\pS\\pZ]", "");System.out.println(str);
DNAMEdfs1431221中國123漢字かどうかのjavaを

Unicode 編碼並不只是為某個字元簡單定義了一個編碼,而且還將其進行了歸類。 
/pP 其中的小寫 p 是 property 的意思,表示 Unicode 屬性,用於 Unicode 正運算式的首碼。

P:標點字元 
L:字母; 
M:標記符號(一般不會單獨出現); 
Z:分隔字元(比如空格、換行等); 
S:符號(比如數學符號、貨幣符號等); 
N:數字(比如阿拉伯數字、羅馬數字等); 
C:其他字元

 

  1.  /**清除數字和空格*/  
  2.     public static  String cleanBlankOrDigit(String str){  
  3.         if(isBlankOrNull(str))return "null";  
  4.         return Pattern.compile("\\d|\\s").matcher(str).replaceAll("");  
  5.     }  
  6.   

 

 

public static final String REG_SPACE_PUNCTUATION = "(\\s)|(\\pP)";
List<News> news = newsDao.findNewsByComsOrInds(query);
// 所有的標點符號空格用Null 字元串替換後 再進行去重
TreeSet<News> newSet = new TreeSet<>((o1, o2) -> o1.getTitle().replaceAll(REG_SPACE_PUNCTUATION, "").compareTo(o2.getTitle().replaceAll(REG_SPACE_PUNCTUATION, "")));
newSet.addAll(news);
news = new ArrayList<>(newSet);

java裡面\\s就是空格, \\pP代表標點符號。 !"#$%&‘()*+,-./:;<=>[email protected][\]^_`{|}~
/pP 其中的小寫 p 是 property 的意思,表示 Unicode 屬性,用於 Unicode 正運算式的首碼。
第一個 \ 是逸出字元
用在上面的replaceAll 方法中 寫第一個\ 就代表匹配Regex了



javaRegex

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.