关于使用 REGEX 在 PHP 字符串中搜索巧合的建议

Suggestion about search coincidences in string with PHP using REGEX

我正在尝试在字符串中搜索这个巧合: 1.我只需要在字符'@'后面取数字,只要这个巧合没有空格,例如:

字符串='This is a test @VVC345RR, text, and more text 12345';
我只想从我的字符串中取出这个 -> 345.

我的例子:

$s = '\"access_token=103782364732640461|2. myemail@domain1.com ZmElnDTiZlkgXbT8e3 @DD234 4Jrw__.3600.1281891600-10000186237005';
$matches = array();
$s = preg_match('/@([0-9]+)/', $s, $matches);
print_r($matches);

这只有在我有一个@和数字时才有效。 谢谢!

也许:

@\D*\K(\d+)

实现你想要的?

这将查找 @、任何非数字,然后捕获数字。 \K 忽略早期匹配。

https://regex101.com/r/gNTccx/1/

我不清楚你所说的 has not spaces 是什么意思,示例字符串中没有空格。