我尝试使用regex从一些semvar中提取v1.2.3的修补程序版本我有一些正则表达式可以匹配v1.2.部分,但我很难得到另一部分,3(我实际上想要回来)我使用^v\d+\.\d+\.来选择第一个零件。我尝试使用负前瞻,然后使用(?!(v\d+\.\d+\.)).*选择它之后的所有内容,但这似乎只是返回v之后的所有内容,而不是group之后的所有内容任何指示将非常感谢,谢谢!
v1.2.3
v1.2.
3
^v\d+\.\d+\.
(?!(v\d+\.\d+\.)).*
v
pbpqsu0x1#
'^(?<=v\d\.\d\.)[[:alnum:]]+'
^
(?<=
\d
\.
)
[[:alnum:]]+
'^v\d+\.\d+\.\K.[[:alnum:]]+'
\d+
\K
K
Check man tr | grep -FA1 '[:' for a POSIX character classes like [[:alnum:]]
man tr | grep -FA1 '[:'
POSIX
[[:alnum:]]
1条答案
按热度按时间pbpqsu0x1#
In this special case:
The regular expression matches as follows:
^
(?<=
v
\d
\.
\d
\.
)
[[:alnum:]]+
A more generic solution than works with any length of digits
The regular expression matches as follows:
^
v
\d+
\.
\d+
\.
\K
K
ept) as a shorter alternative to using a look-behind assertion: look arounds and Support of K in regex[[:alnum:]]+
Check
man tr | grep -FA1 '[:'
for aPOSIX
character classes like[[:alnum:]]