正则表达式帮助。不能自己解决

Regex helping. Can't solve this by myself

我需要正则表达式方面的帮助。 这是文字,我有:

#1234 10% commet@timing:information and other activity2@timing
#12d34 10% commet@timing:information and other activity2@timing
#3132 10% testing@1.10:test commit  frontend@44min:other comments  
#3132 10% testing@1.10:test commit 2 

因此,我需要获取每个 text@text:text with spacestext@text with spaces 条目。 这就是我现在拥有的:https://regex101.com/r/zgILCE/1
我的正则表达式 /(\w*)\@([\w.]*)\:((\w|\s)*) / 运行不正常。

更新。 我需要正则表达式匹配这个: 一个@一个:一些文字 一一 一个@一个:一个

图例:

一个 - 一个词(可能有数字)

一些文本 - 常规文本(可能带有数字)

我会使用以下正则表达式:

\s+\S+\@\S+(\s+|$)

上面的 RegEx 匹配白色 spaces,然后是任何非 space 字符后跟一个 @ 符号,然后是任何非 space 字符,然后是 spaces。这使得它通过 : 匹配到下一个 space。

如果文件中的最后一项在文件末尾没有行结束符,末尾的 $ 将使其仍然匹配。否则,使用全局匹配修饰符 \s 无论如何都会匹配垂直的白色-space(也就是行尾)

如果根据评论您真的只想匹配一个白色 space 而不是文档中有很多:

\s\S+\@\S+(\s|$)

我想你在找:

(?<!\S)(\w+)@([\w.]*:)?(\w+(?:\h\w+)*)(?!\S)

demo

详情:

(?<!\S) # not preceded by a character that isn't a whitespace
(\w+)
@
([\w.]*:)? # according to your requirements this part is optional
(
    \w+ (?:\h\w+)* # way to include eventual single spaces between words
)
(?!\S) # not followed by a character that isn't a whitespace
<?php
$string1='#3132 10% testing@1.10:test commit  frontend@44min:other comments ';


$string=explode(' ',$string1);

echo '<pre>';

$myArray=array();
foreach ($string as $row){
    if (strpos($row, '@') !== false) {
        $myArray[]=$row;
    }
}

print_r($myArray);

我将提供更 php 的解决方案,而不是正则表达式。我正在分解你的字符串以获得一个数组,然后我用循环搜索数组字段以找到 @。在我这样做之后,我只是 return 字段。

输出为:

Array
(
    [0] => testing@1.10:test
    [1] => frontend@44min:other
)