且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP正则表达式不适用于数据库中的字符串

更新时间:2022-03-26 22:31:22

事实证明您的字符串中有 Unicode 破折号.要匹配所有 Unicode 破折号,请使用

It turns out you have Unicode dashes in your strings. To match all Unicode dashes, use

/[\p{Pd}\xAD]/u

查看正则表达式演示

\p{Pd} 匹配 Unicode Character Category 'Punctuation, Dash' 但是软连字符 \xAD,因此它应该与 \p 结合{Pd} 在字符类中.

The \p{Pd} matches any hyphen in the Unicode Character Category 'Punctuation, Dash' but a soft hyphen, \xAD, hence it should be combined with \p{Pd} in a character class.

/u 修饰符使模式识别 Unicode,并使正则表达式引擎将输入字符串视为 Unicode 代码点序列,而不是字节序列.

The /u modifier makes the pattern Unicode aware and makes the regex engine treat the input string as Unicode code point sequence, not a byte sequence.