preg_match 所有单词以@ 开头? [英] preg_match all words start with an @?
问题描述
我对正则表达式不是很熟悉,所以我不得不问你:
i'm not very firm with regular Expressions, so i have to ask you:
如何使用 PHP 找出字符串是否包含以 @ 开头的单词??
How to find out with PHP if a string contains a word starting with @ ??
例如我有一个像这是给@codeworxx"这样的字符串???
e.g. i have a string like "This is for @codeworxx" ???
我很抱歉,但我没有起点:(
I'm so sorry, but i have NO starting point for that :(
希望能帮到你.
谢谢,萨沙
好的,谢谢你的结果 - 但我犯了一个错误 - 如何在 eregi_replace 中实现???
okay thanks for the results - but i did a mistake - how to implement in eregi_replace ???
$text = eregi_replace('/\B@[^\B]+/','<a href="\\1">\\1</a>', $text);
不起作用??!?
为什么?我不需要输入与模式相同的表达式吗?
why? do i not have to enter the same expression as pattern?
推荐答案
Match 任何东西,在 @
前面有一些空格,后面跟着一些不是空格的东西:
Match anything with has some whitespace in front of a @
followed by something else than whitespace:
$ cat 1812901.php
<?php
echo preg_match("/\B@[^\B]+/", "This should @match it");
echo preg_match("/\B@[^\B]+/", "This should not@ match");
echo preg_match("/\B@[^\B]+/", "This should match nothing and return 0");
echo "\n";
?>
$ php 1812901.php
100
这篇关于preg_match 所有单词以@ 开头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!