我有一个文本字符串,其中包含一个重复模式,每个重复之间用.
(点)字符隔开.模式may
以_123
结尾(下面是一个数字序列),我想在专用捕获组中捕获这些数字.
The RegEx (ECMAScript) I have built mostly works:
https://regex101.com/r/iEzalU/1
/(label(:|\+))?(\w+)(?:_(\d+))?/gi
然而,(\w+)
部分表现得贪婪,并超越了(?:_(\d+))?
部分.
添加?
以生成\w+
非贪婪(\w+?)
有效,但现在我 for each 与\w
匹配的角色都有一个捕获令牌
How can I make this regex such that \w+
acts greedy but still does not overtake the _(\d+)
part?
Otherwise, is it possible to capture all tokens matched by the non-greedy \w+?
, as a single match? (some capturing/non-capturing groups magic?)