In the recent retrieval work, the user needs to input the request and return the result. Because it is difficult to predict the user's input content, if no filtering is added, an exception may be thrown during the retrieval phase.
User input may have different styles. The most common is the input with various punctuation marks. How to filter?
I saw a post on the csdn Forum. After combining it, I got the following regular expression, which may help you solve the problem:
\ PP | \ PS
We use an example to demonstrate the regular expression usage:
Public static void main (string [] ARGs ){
String string = "test <>"! * (^) $ % ~! @ # $... & % ¥-+ = ,.,; ''" ": · 'Text ";
System. Out. println (string. replaceall ("\ PP | \ Ps ",""));
}
Output result:
Test text
The reference content is as follows:
Unicode encoding not only defines an encoding for a character, but also classifies it.
/PP the lower-case P indicates the Unicode attribute, which is used for the prefix of the Unicode positive expression.
Uppercase P indicates one of the seven character attributes of the Unicode Character Set: punctuation.
The other six are
L: letter;
M: Mark the symbol (generally it will not appear separately );
Z: delimiter (for example, space, line feed, etc );
S: Symbols (such as mathematical symbols and currency symbols );
N: Numbers (such as Arabic numerals and Roman numerals );
C: other characters
The above seven are attributes, and there are several sub-attributes under the seven attributes for further subdivision.
In Java, the Regular Expression data for Unicode is provided by Unicode organizations.
Unicode Regular Expression standard (all sub-attributes can be found)
Http://www.unicode.org/reports/tr18/
For the definition of UNICODE character attributes, you can see what attributes a character has.
Http://www.unicode.org/Public/UNIDATA/UnicodeData.txt
This text document contains a single character. The first column is Unicode encoding, the second column is the character name, and the third column is the Unicode attribute,
And other characters.