My regex is causing a stack overflow in Java; what am I missing?

前端 未结 4 1821
攒了一身酷
攒了一身酷 2021-01-18 13:32

I am attempting to use a regular expression with Scanner to match a string from a file. The regex works with all of the contents of the file except for this line:

         


        
4条回答
  •  情歌与酒
    2021-01-18 13:51

    Try this simplified version of your regex that removes some unnecessary | operators (which might have been causing the regex engine to do a lot of branching) and includes beginning and end of line anchors.

    static final String ANIMAL_INFO_REGEX = "^([a-zA-Z]+) *= *\"([a-zA-Z_. ]+)\"$";
    

提交回复
热议问题