我正在尝试编写一个正则表达式匹配器,其中字符串应以 'Feb' 开头,有一个空格,然后是 2 位数字。
String x = "Feb 04 |";
String regex = "^Feb d{2}";
Pattern p = Pattern.compile(regex);
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(x);
while (matcher.find())
{
System.out.print("FOUND");
}
'String regex = "^Feb";'
可以很好地检测它是否以 Feb 开头,但尝试检测是否有空格后跟 2 位数字。
最佳答案
正则表达式模式 ^Feb\s\d{2}
匹配 Feb、一个空格和两个数字。
[编辑]
^Feb\s\d{2}.*$
如果您想匹配完整字符串
关于java - 正则表达式文本日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55791484/