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
Regex 2个正则表达式,用于提取版本号和版本名_Regex_Pcre - Fatal编程技术网

Regex 2个正则表达式,用于提取版本号和版本名

Regex 2个正则表达式,用于提取版本号和版本名,regex,pcre,Regex,Pcre,我真的很难理解正则表达式 我有这个字符串: Windows SERVERMAIN 10.0.14393 Microsoft Windows Server 2016 Standard x64 Microsoft Windows Server 2016 Datacenter x64 - 10.0.14393 我需要创建两个正则表达式 第一个应该返回第二个空格之后第三个空格之前的字符串部分,因此我只剩下: 10.0.14393 Microsoft Windows Server 2016 Stan

我真的很难理解正则表达式

我有这个字符串:

Windows SERVERMAIN 10.0.14393 Microsoft Windows Server 2016 Standard x64
Microsoft Windows Server 2016 Datacenter x64 - 10.0.14393
我需要创建两个正则表达式

第一个应该返回第二个空格之后第三个空格之前的字符串部分,因此我只剩下:

10.0.14393
Microsoft Windows Server 2016 Standard x64
第二个应该在第三个空格后返回所有内容,因此我只剩下:

10.0.14393
Microsoft Windows Server 2016 Standard x64
有人能帮我吗?到目前为止,我只能使用:

\s+\w+\s(.*)
这给了我:

SERVERMAIN 10.0.14393 Microsoft Windows Server 2016 Standard x64
更新1 在@rock321987的帮助下,我回顾了如何实现这一点

我现在有了这个字符串:

Windows SERVERMAIN 10.0.14393 Microsoft Windows Server 2016 Standard x64
Microsoft Windows Server 2016 Datacenter x64 - 10.0.14393
我想将其分为两组:

Microsoft Windows Server 2016 Datacenter x64

10.0.14393

正则表达式1细分

正则表达式2细分

编辑:如果您的工具允许,这也可以在单个正则表达式中完成

^.*?[ ]+.*?[ ]+(.*?)[ ]+(.*)$
编辑1:如果需要,也可以使用
\K

^.*?[ ]+.*?[ ]+\K([^ ]+)

在尝试使用Regex 1时,它显示完全匹配和组1,我需要它就像完全匹配一样,如果这有意义的话?您需要从您的语言中提取
Group 1
。我不知道如何做?在输出时,我把“\0”作为第一个捕获组使用
\1
,就在我写了我的评论之后,我认为这可能很简单,于是尝试了一下。非常感谢!