更新时间:2023-11-26 21:09:34
Java将处理\在字符串中作为起始的转义序列。请确保您使用\,而不是(这样你得到的字符串中的实际字符\),你应该没问题。
Java will treat \ inside a string as starting an escape sequence. Make sure you use \ instead (so that you get an actual \ character in the string) and you should be ok.
快速更新:
作为艾蒂安指出,如果你真的想在正则表达式本身就是一个\,你需要使用\\,因为这将产生\在字符串,这将产生\在正则表达式。
Quick Update:
As Etienne points out, if you actually want a \ in the RegEx itself, you'll need to use \\, since that will produce \ in the string, which will produce \ in the RegEx.
修正后您的正则表达式:
Your regex after correction:
String regEx ="^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\\d{2}$";