Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.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获取文本中“后”的所有匹配字符串@&引用;性格_Php_Regex - Fatal编程技术网

php获取文本中“后”的所有匹配字符串@&引用;性格

php获取文本中“后”的所有匹配字符串@&引用;性格,php,regex,Php,Regex,我有一个函数,我希望设置文本从文本返回一些匹配字符串: function get_matches(){ $string = "@text1 @text2 any text here #text3 #text4 @text5 "; // Set the test string. // Set the regex. $regex = 'WHAT IS THE REGEX HERE'; // Run the regex with preg_match_all

我有一个函数,我希望设置文本从文本返回一些匹配字符串:

function get_matches(){
    $string = "@text1 @text2 any text here #text3 #text4 @text5 ";
    // Set the test string.

    // Set the regex.
    $regex = 'WHAT IS THE REGEX HERE';

    // Run the regex with preg_match_all.
    preg_match_all($regex, $string, $matches);

    // Dump the resulst for testing.
    echo '<pre>';
    print_r($matches);
    echo '</pre>';

}

如何编写适当的正则表达式以获得正确的结果。

此正则表达式适用于您:

Array
(
    [0] => Array
        (
            [0] => @text1
            [1] => @text2
            [2] => @text4
            [3] => @text5
        )

    [1] => Array
        (
            [0] => text1
            [1] => text2
            [2] => text4
            [3] => text5
        )

)
输出:


此正则表达式适用于您:

Array
(
    [0] => Array
        (
            [0] => @text1
            [1] => @text2
            [2] => @text4
            [3] => @text5
        )

    [1] => Array
        (
            [0] => text1
            [1] => text2
            [2] => text4
            [3] => text5
        )

)
输出:


此正则表达式适用于您:

Array
(
    [0] => Array
        (
            [0] => @text1
            [1] => @text2
            [2] => @text4
            [3] => @text5
        )

    [1] => Array
        (
            [0] => text1
            [1] => text2
            [2] => text4
            [3] => text5
        )

)
输出:


此正则表达式适用于您:

Array
(
    [0] => Array
        (
            [0] => @text1
            [1] => @text2
            [2] => @text4
            [3] => @text5
        )

    [1] => Array
        (
            [0] => text1
            [1] => text2
            [2] => text4
            [3] => text5
        )

)
输出:



@text^#$*!&废话
?对于
@foo
?对于
@text^#$*!&废话
?对于
@foo
?对于
@text^#$*!&废话
?对于
@foo
?对于
@text^#$*!&废话
?对于
@foo
?我们如何使用一个数组?我的意思是:数组([0]=>text1[1]=>text2[3]=>text5)@Ghalonline只需放置一个
$matches=array\u merge($matches[1])打印之前!请告诉我,没有“@”怎么能打印结果,@Ghalonline就像我说的那样,只需放一行:
$matches=array\u merge($matches[1])在预匹配所有行之后
(?我们如何使用一个数组?我的意思是:数组([0]=>text1[1]=>text2[3]=>text5)@Ghalonline只需在打印前放入一个
$matches=array\u merge($matches[1]);
!请告诉我如何在没有“@”的情况下打印结果正如我所说的,@Ghalonline只需在preg\u matches\u all行之后放置一行:
$matches=array\u merge($matches[1]);
(?我们如何使用一个数组呢?我的意思是:数组([0]=>text1[1]=>text2[3]=>text5)@Ghalonline只需放置一个
$matches=array\u merge($matches[1])
在打印之前!请告诉我,如果没有“@”@Ghalonline,您如何打印结果?正如我所说,只需将这一行:
$matches=array\u merge($matches[1]);
放在preg\u match\u all行之后!
(?我们如何使用一个数组?我的意思是:array([0]=>text1[1]=>text2[3]=>text5)@ghalionline在打印之前只需在打印结果之前放一行:
$matches=array\u merge($matches[1]);
请告诉我如何在没有“@”的情况下打印结果。@ghalionline就像我说的那样,只需在preg\u match\u all行之后放一行:
$matches=array\u merge($matches[1])