Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.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,我一直在浏览这个网站寻求帮助,但还没有找到我想要的。假设我有一个具有以下值的textarea @3115 Hello this is a test post. @115 Test quote 我试图在PHP中找到一种使用正则表达式的方法,即使有多个符号,它也能得到@符号后面的数值。我对这件事很难理解。我想将从正则表达式返回的值存储到一个数组中是我要寻找的?(以preg\u match函数为例,但函数不重要,其中的正则表达式:) 这将查找一个@字符,然后查找任何数值的\d,然后+意味着捕捉[数

我一直在浏览这个网站寻求帮助,但还没有找到我想要的。假设我有一个具有以下值的textarea

@3115
Hello this is a test post.

@115
Test quote
我试图在PHP中找到一种使用正则表达式的方法,即使有多个符号,它也能得到@符号后面的数值。我对这件事很难理解。我想将从正则表达式返回的值存储到一个数组中是我要寻找的?

(以
preg\u match
函数为例,但函数不重要,其中的正则表达式:)

这将查找一个
@
字符,然后查找任何数值的
\d
,然后
+
意味着捕捉[数值]一次或多次。
()
使其成为一个捕获组,因此只返回找到的号码,而不返回其前面的
@

试试这个:

$str = <<<EOF
@3115
Hello this is a test post.

@115
Test quote
EOF;

preg_match_all('/@(\d+)/', $str, $matches);
var_dump($matches[1]); // Returns an array like ['3115', '115']

$str=@Martin是的,它总是在@symbol后面的数字。实际上,你能澄清一下你想要的是所有的值还是第一个吗?我以为你想要所有的,但重读你的帖子却模棱两可?
$str = <<<EOF
@3115
Hello this is a test post.

@115
Test quote
EOF;

preg_match_all('/@(\d+)/', $str, $matches);
var_dump($matches[1]); // Returns an array like ['3115', '115']