Why preg_match(“/[^(22|75)]/”, “25”) returns false?

前端 未结 5 1702
误落风尘
误落风尘 2021-01-29 08:31

I want to test that a given string does not belong to the following group of strings: 22 75.

Could anyone please tell why PHP\'s preg_match(\"/[^(22|75)]/\

5条回答
  •  渐次进展
    2021-01-29 09:17

    ^ inside of [...] is a negation of a character list. (22|76)

    Regex multiple character negation is a very tricky subject and can't be easily resolved.

    But you could invert the return result of preg_match function ie.:

    if(!preg_match('@22|76@', '25', $matches))
        doSomething();
    

提交回复
热议问题