How to match “any character” in regular expression?

前端 未结 11 674
忘了有多久
忘了有多久 2020-11-27 09:23

The following should be matched:

AAA123
ABCDEFGH123
XXXX123

can I do: \".*123\" ?

11条回答
  •  猫巷女王i
    2020-11-27 10:25

    Yes that will work, though note that . will not match newlines unless you pass the DOTALL flag when compiling the expression:

    Pattern pattern = Pattern.compile(".*123", Pattern.DOTALL);
    Matcher matcher = pattern.matcher(inputStr);
    boolean matchFound = matcher.matches();
    

提交回复
热议问题