有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java正则表达式文本日期

我正在尝试编写一个正则表达式匹配器,其中字符串应该以'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开头,但是尝试检测后面有一个空格,后跟两个数字


共 (1) 个答案

  1. # 1 楼答案

    正则表达式模式^Feb\s\d{2}匹配Feb、一个空格和两个数字

    [编辑]

    ^Feb\s\d{2}.*$如果要匹配完整字符串