How regular expression OR operator is evaluated

后端 未结 2 563
忘了有多久
忘了有多久 2021-01-18 08:43

In T-SQL I have generated UNIQUEIDENTIFIER using NEWID() function. For example:

723952A7-96C6-421F-961F-80E66A4F29D2

Then,

2条回答
  •  [愿得一人]
    2021-01-18 09:20

    Your Regex ^.{8}|.{12}$|.{4} evaluates to:

    Starting with any character except \n { Exactly 8 times }

    OR any character except \n { Exactly 12 times }

    OR any character except \n { Exactly 4 times } globally

    This means that anything after 4 characters in a row will be matched because somewhere in a string of >4 characters there are 4 characters in a row.

    1 [false]

    12 [false]

    123 [false]

    1234 [true]

    12345 [true]

    123456 [true]

    1234567 [true]

    12345678 [true]

    123456789 [true]

    1234567890 [true]

    12345678901 [true]

    123456789012 [true]

    You might be looking for:

    ^.{8}$|^.{12}$|^.{4}$

    Which gives you:

    1 [false]

    12 [false]

    123 [false]

    1234 [true]

    12345 [false]

    123456 [false]

    1234567 [false]

    12345678 [true]

    123456789 [false]

    1234567890 [false]

    12345678901 [false]

    123456789012 [true]

提交回复
热议问题