Method of Java regular expression processing special character escape

Regular requires escape characters

'$','(',')','*','+','.',' [',']','?','\\','^',' {','}','|'

Abnormal phenomena:

java. util. regex. PatternSyntaxException: Dangling Meta. character '*' near index 0

resolvent

Add \ \ escape to special characters.

Note: Although [] can be used under some conditions, it will be reported as follows when the (, [, {range boundary start characters do not match:

Abnormal phenomenon

java. util. regex. PatternSyntaxException: Illegal repetition near index 50

The special word code of Java filtering regular expression is as follows (Note: \ \ the first replacement is required, otherwise there will be a logic bug when replacing the replace method)

summary

The above is the whole content of this article. I hope the content of this article can bring some help to your study or work. If you have any questions, you can leave a message.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>