Regex - check if input still has chances to become matching

前端 未结 11 1474
天命终不由人
天命终不由人 2020-12-05 00:51

We\'ve got such regexp:

var regexp = /^one (two)+ three/;

So only string like \"one two three\" or \"one two three four\

11条回答
  •  忘掉有多难
    2020-12-05 01:20

    Still not 100% sure what you are asking for, but you can also nest them, like this:

    var regexp = /^(one)+((\s+two)+((\s+three)+((\s+four)+)?)?)?$/;
    

    Matches:

    • one
    • one two two
    • one two two three
    • one two two three three four

    Does not match:

    • one three

提交回复
热议问题