regular expressions: match x times OR y times

后端 未结 4 1463
面向向阳花
面向向阳花 2020-12-01 17:46

Lets say I need to match a pattern if it appears 3 or 6 times in a row. The closest I can get is something like \\d{3,6} but that doesn\'t quite do what I need.

\'12

4条回答
  •  心在旅途
    2020-12-01 18:39

    How about:

    (\d\d\d){1,2}
    

    although you'll also need guards at either end which depend on your RE engine, something like:

    [^\d](\d\d\d){1,2}[^\d]
    

    or:

    ^(\d\d\d){1,2}$
    

提交回复
热议问题