Regular Expressions are a very powerful tool. We can do a lot of work that requires a lot of code.
I have never systematically studied regular expressions, and I usually use regular expressions for temporary queries (ps is mainly because I am too lazy !). So a lot of knowledge is vague.
Today, when writing a java program, we use regular expressions to remove duplicate content. For example:
Public static void main (String [] args) {Pattern pat = Pattern. compile ("(\ w +), \ 1"); String test = "Let's get married, let's get married"; Matcher m = pat. matcher (test); if (m. find () {System. out. println ("match"); System. out. println (m. group (1);} else System. out. println ("no match ");}
The result is always no match.
Later, I checked it on the Internet to find out that the platform had different interpretations of the regular expression metacharacters. In java, \ w cannot match Chinese characters. \ W must be used to match Chinese characters. This is different from the original regular expression.
After modification, the expression can be correctly matched.