include dot(.) and hyphen(-) in a regex

后端 未结 4 1113
误落风尘
误落风尘 2021-01-29 12:56
 if(preg_match(\'/[^a-z\\-0-9]/i\', $value))

    {
    echo \"\";
}

how

4条回答
  •  感情败类
    2021-01-29 13:10

    The hyphen doesn't need to be escaped if it's the first or last in the character class.
    The dot also doesn't need to escaped when used inside a character class [] i.e.:

    /[^a-z.0-9-]/i
    

    NOTES:

    Apart from the above, the meta characters that also need to be escaped inside a character class are:

    ^ (negation)
    - (range)
    ] (end of the class)
    \ (escape char)
    

提交回复
热议问题