Difference between regex quantifiers plus and star

前端 未结 5 1789
轮回少年
轮回少年 2020-11-27 08:37

I try to extract the error number from strings like \"Wrong parameters - Error 1356\":

 Pattern p = Pattern.compile(\"(\\\\d*)\");
 Matcher m =          


        
5条回答
  •  难免孤独
    2020-11-27 09:14

    but none if necessary means that it will not break the regex pattern if there is no match. So \d* means it will match zero or more occurrences of digits.

    For eg.

    \d*[a-z]*
    

    will match

    abcdef
    

    but \d+[a-z]*

    will not match

    abcdef
    

    because \d+ implies that at least one digit is required.

提交回复
热议问题