JAVA Delete/purge/filter punctuation (all Chinese and English punctuation) regular expression __java

Source: Internet
Author: User
Turn from: http://blog.csdn.net/harryhuang1990/article/details/11888293

In the text analysis of the time we often need to filter out the stop words, punctuation and so on, this article to explain how to identify and delete all the punctuation in the text. Here are three feasible regular expression scenarios, children's shoes try it ^_^ [Java]View plain Copy (1) s.replaceall ("\\p{punct}", "");         (2) S.replaceall ("\\pP", ""); (3) S.replaceall ("\\p{p}", "");

(1) Do not fully understand all punctuation, (2) and (3) equivalence can be completely clear punctuation (both in Chinese and English can be clear) it should be noted that there are some systems do not think that the punctuation of half-width and full-width symbols can not be cleared, as follows: [Java]View plain copy +~$ ' ^=|<>~ ' $^+=| <> ¥x
After modification: [Java]View plain Copy (2) S.replaceall ("[\\pp+~$ ' ^=|<>~ ' $^+=| <> ¥x]", ""); (3) S.replaceall ("[\\p{p}+~$ ' ^=|<>~ ' $^+=| <> ¥x]", "");


The above three scenarios are given in the form of Unicode punctuation properties of regular expressions, you can remove all punctuation, including full-width, half-width, horizontal, vertical and other punctuation.

Note that full-angle single quotation marks and double quotation marks are not supported in an environment that is JDK 5 or below. In JDK 6, the PI and Pf two Unicode child properties are added so that they can be replaced.

This can be done in the version below JDK 6: [Java]View plain Copy s = S.replaceall ("[\\pP" ""] "" ");
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.