Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php regex-在字符串和任意位置之间匹配字符_Php_Regex - Fatal编程技术网

Php regex-在字符串和任意位置之间匹配字符

Php regex-在字符串和任意位置之间匹配字符,php,regex,Php,Regex,我想匹配所有“@”项,不包括引号之间的项 我试过: @name "@new other content" "@" @here and here@ 它部分工作,与“@”不匹配,但与“@新的其他内容”匹配 我在PHP中与“preg_replace”一起使用 谢谢你的帮助 更新: 在这种情况下,我想匹配@on:@name、@here,here@仅…如果“@”总是直接在“之后,那么您可以使用 (?!\")\@(?!\") 看到了吗 这只是匹配包含@的子字符串,当前面有偶数个“ahead”时 小心:如

我想匹配所有“@”项,不包括引号之间的项

我试过:

@name "@new other content" "@" @here and here@
它部分工作,与“@”不匹配,但与“@新的其他内容”匹配

我在PHP中与“preg_replace”一起使用

谢谢你的帮助

更新:

在这种情况下,我想匹配@on:
@name、@here,here@
仅…

如果“@”总是直接在“之后,那么您可以使用

(?!\")\@(?!\")
看到了吗

这只是匹配包含@的子字符串,当前面有偶数个“ahead”时


小心:如果字符串中的任何地方有不匹配的引号,它将失败。

什么应该由
Outside@“in@side”Outside@
匹配?谢谢。我不能假设这种情况……它应该在双引号之间的任何位置匹配@。@MarizMelo:我添加了另一个解决方案。
(?<!\")\@
[^"\s]*@[^"\s]*(?=[^"]*(?:"[^"]*"[^"]*)*$)