Delete/clear/filter regular expressions of punctuation marks (all Chinese and English Punctuation Marks)-Desktop Search Development Notes [experience accumulation]

Source: Internet
Author: User

During text analysis, we often need to filter out deprecated words and punctuation marks. This article describes how to identify and delete all punctuation marks in the text. The following are three feasible Regular Expression solutions. Let's try ^_^ [java] (1) s. replaceAll ("\ p {Punct}", ""); (2) s. replaceAll ("\ pP", ""); (3) s. replaceAll ("\ p {P}", ""); (1) cannot fully understand all punctuation marks, (2) and (3) it is equivalent to clear all punctuation marks (both Chinese and English). You must note that there are still some systems that do not consider punctuation halfwidth and fullwidth symbols to be irretrievable, as shown below: [java] ++ ~ $ '^ = | <> ~ Updated $ ^ + = | <> ¥ × after modification: [java] (2) s. replaceAll ("[\ pP ++ ~ $ '^ = | <> ~ Activities $ ^ + = | <> ¥ ×] "," "); (3) s. replaceAll (" [\ p {P} + ~ $ '^ = | <> ~ `$ ^ + = | <> ¥ ×] "," "); The preceding three schemes use regular expressions that use the Unicode punctuation attribute, you can remove all punctuation marks, including full-width, half-width, horizontal, and vertical. Note that full-angle single-quotation marks and double quotation marks cannot be replaced in JDK 5 or lower environments. Because the Pi and Pf Unicode sub-attributes are added to JDK 6, they can be replaced. In JDK 6 or lower versions, you can do this: [java] s = s. replaceAll ("[\ pP'' "]", "");

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.