Java Regular Expression Matcher doesn't find all possible matches

前端 未结 2 1643
遥遥无期
遥遥无期 2021-01-21 06:53

I was looking at a code at TutorialsPoint and something has been bothering me since then... take a look at this code :

import java.util.regex.Matcher;
import jav         


        
2条回答
  •  一向
    一向 (楼主)
    2021-01-21 07:23

    (.*?)(\\d+)(.*)
    

    Make your * greedy quantifier non greedy by putting *?.

    Because your first group (.*) is greedy it will capture evrything and will leave just one 0 for \d to capture.If you make it non greedy it will give you expected results.See demo.

    https://regex101.com/r/tX2bH4/53

提交回复
热议问题