( 之后的正则表达式匹配号 [英] regex match number after (

查看:34
本文介绍了( 之后的正则表达式匹配号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用正则表达式来匹配开括号 '(' 字符后的可变长度的数字.

我试过了

\(\d+

但是那个正则表达式在匹配中包含括号.我如何排除它?

我正在使用 sublime text regex 引擎来进行匹配.

解决方案

您可以使用

您可以使用 \K匹配重置"运算符来解决后视中的长度限制,因为 \K 只是在匹配的位置截断"匹配使用时,省略与其左侧模式匹配的所有文本:

\(\K\d+

[]

请注意,\K 实际上不是后视等价物,因为它之前的文本被消耗,而后视不消耗文本.

I am trying to use regex to match a a variable length of digits after the open bracket '(' character.

I have tried

\(\d+

But that regex includes the bracket in the match. How do I exclude it?

I am using sublime text regex engine to do the match.

解决方案

You may use a positive lookbehind:

(?<=\()\d+

There is one limitation here: you can only have a pattern of known width in the lookbehind. You may use (?<=\(|\s{5})\d+, but you cannot use (?<=\d:\s*)\d+.

You may use \K "match reset" operator to work around the length limit in the lookbehind since \K just "truncates" the match at the place where it is used, all text matched by the pattern to the left of it is omitted:

\(\K\d+

[]

Note that \K is not actually a lookbehind equivalent since the text before it is consumed while lookbehinds do not consume text.

这篇关于( 之后的正则表达式匹配号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆