说明
^(?:[^(]*\([^)]*\)){2}[^(]*\(\s*\K[0-9]{2}[.][0-9]{3}
^^^
在{2}
的数量可以根据需要而改变,然后将表达将选择该串中的N + 1%的值。如果选择0
,那么表达式将匹配第一个百分比,如果您选择1
则表达式将匹配第二个百分比...等等。
该表达式假设语言支持\K
正则表达式命令,该命令强制引擎删除与之相匹配的所有内容,直到\K
。
例
现场演示
https://regex101.com/r/oX0mJ4/1
示例文本
5 Secs (14.2725%) 60 Secs (12.630%) 300 Secs (15.5993%)
样品匹配
使用写入的表达式会返回第3个条目。
15.599
说明
NODE EXPLANATION
----------------------------------------------------------------------
^ the beginning of a "line"
----------------------------------------------------------------------
(?: group, but do not capture (2 times):
----------------------------------------------------------------------
[^(]* any character except: '(' (0 or more
times (matching the most amount
possible))
----------------------------------------------------------------------
\( '('
----------------------------------------------------------------------
[^)]* any character except: ')' (0 or more
times (matching the most amount
possible))
----------------------------------------------------------------------
\) ')'
----------------------------------------------------------------------
){2} end of grouping
----------------------------------------------------------------------
[^(]* any character except: '(' (0 or more times
(matching the most amount possible))
----------------------------------------------------------------------
\( '('
----------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ") (0 or
more times (matching the most amount
possible))
----------------------------------------------------------------------
\K 'K'
----------------------------------------------------------------------
[0-9]{2} any character of: '0' to '9' (2 times)
----------------------------------------------------------------------
[.] any character of: '.'
----------------------------------------------------------------------
[0-9]{3} any character of: '0' to '9' (3 times)
----------------------------------------------------------------------
什么是你真正想从你给的例子中提取?顺便说一句,我认为你将需要摆脱你提到的正则表达式中的一堆东西。 –
几乎没有关于什么编程语言或shell的信息。另外,如果你有一个shell,为什么你说“我没有访问其他shell工具”?通常在系统上安装大量的shell工具。也许你可以填写我们的细节? – Kusalananda
一个几乎相同的问题:http://stackoverflow.com/questions/37924545/return-the-next-nth-result-w-after-a-hyphen-globally/37924922#37924922 –