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

前端 未结 5 1727
误落风尘
误落风尘 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:20

    Your regex is asking "does the string contain a character that is not (, 2, 7, 5, | or )?"

    This is obviously not what you want.

    Try this:

    if( !in_array("25", array("22","75")))
    

提交回复
热议问题