你好,我想匹配下一行中的“@”,
create@create_time:"2012-05-30 21:14:35.0",update_time:"2012-05-31 22:05:46.0"
preg_replace("@", "", $content)
preg_replace("\@", "", $content)
它们都不工作。
最佳答案
对于后代:如果有人因为对作为其他人代码一部分的正则表达式中的 at 符号的使用感到困惑而无意中发现了这一点,@
偶尔用作开始和结束 regex-delimiter .下面的引述还涉及到为什么 OP 尝试匹配文字“@”失败(强调我的):
When using the PCRE functions, it is required that the pattern is enclosed by delimiters. A delimiter can be any non-alphanumeric, non-backslash, non-whitespace character.
换句话说,任何正则表达式字符串必须以一个由字符类[^A-Za-z\s\\]
标识的匹配字符开始和结束。或者——如果你觉得你可以处理它们的使用可能给你带来的任何头痛——一对匹配的分组字符<>
{}
[]
()
.
关于php preg_match 在标志处,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11023790/