How does {m}{n} (“exactly n times” twice) work?

前端 未结 7 659
自闭症患者
自闭症患者 2021-02-03 16:23

So, some way or another (playing around), I found myself with a regex like \\d{1}{2}.

Logically, to me, it should mean:

(A digit exac

7条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-03 17:04

    At first I was surprised this doesn't throw a PatternSyntaxException.

    I can't base my answer on any facts, so this is just an educated guess:

    "\\d{1}"    // matches a single digit
    "\\d{1}{2}" // matches a single digit followed by two empty strings
    

提交回复
热议问题