Difference between regex quantifiers plus and star

前端 未结 5 1804
轮回少年
轮回少年 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:12

    \d* Eat as many digits as possible (but none if necessary)
    

    \d* means it matches a digit zero or more times. In your input, it matches the least possible one (ie, zero times of the digit). So it prints none.

    \d+
    

    It matches a digit one or more times. So it should find and match a digit or a digit followed by more digits.

提交回复
热议问题