1, the first is to explain some easily confused symbols
\w Matches any word character.
\w Matches any non-word character.
If it is in Java, double quotation marks are required to \\w, and here you need to pay attention to case sensitivity.
\s is the space represented by
*the character is a quantifier this means "zero or more times".
There is also a + quantifier meaning ' one or more times ',
A ? quantifier meaning "zero or one time",
2, explain the problem of Chinese processing
Chinese and Japanese don ' t use the regular space character '. The languages use their own which is the same width as the characters. This was the character here ", you should write a manual trim function to check for that character at the beginning and E nd of the string.
Able to directly use the character if you convert your code file to Unicode (if Java would allow). Otherwise you'll need to find the Unicode character code for "and check if the character code is at the beginning or End of the string.
The following link tells us, the ideographic space is 0xe38080 in UTF-8 and 0x3000 in UTF-16, and that Java ' s CHARACTE R.isspacechar () function would return true. I would have thought String.Trim () would has used this property to determine whether or not to trim though.
Then, for example, given a Chinese character, return the code Gurva
"" in Java in, String the GetBytes () method is to get an operating system by default in the encoded format of the byte array. This means that there is no way to return something under the OS! (so it is not recommended)
The String.getbytes (string decode) method returns a byte array representation of a string under the encoding according to the specified decode encoding, noting that the encoding decode when writing Charsets.utf_8
Such as
byte[] B_GBK = "Medium". GetBytes ("GBK");
byte[] B_utf8 = "Medium". GetBytes ("UTF-8");
byte[] b_iso88591 = "Medium". GetBytes ("iso8859-1");
The byte array in the GBK, UTF-8, and Iso8859-1 encodings is returned for the character "medium" respectively, at which time the length of the B_GBK is 2,b_utf8 and the length of 3,b_iso88591 is 1.
In contrast to GetBytes, this "medium" Word can be restored by means of the new String (byte[], decode), and the NewString (byte[], decode) is actually using decode-specified encoding to byte[] parsed into a string.
String S_GBK = new String (B_GBK, "GBK");
String S_utf8 = new String (B_utf8, "UTF-8");
String s_iso88591 = new String (b_iso88591, "iso8859-1");
Java Regular Expressions