Sublime Text 中的非捕获组正则表达式不起作用 [英] Non-capturing group reg-ex in Sublime Text not working

查看:89
本文介绍了Sublime Text 中的非捕获组正则表达式不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试删除标签之间的所有残留空间.所以我尝试使用正则表达式选择它们.

I'm trying to remove all lingering spaces between tags. So I try to select them with a regex.

<span>        </span>
      ^^^^^^^^

我的正则表达式是 (?:>) +(?:<).我正在尝试使用非捕获组从选择中排除 ><,但它似乎不起作用.

My regex is (?:>) +(?:<). I'm trying to exclude the > and < from the selection with a non-capturing group, but it doesn't seem to be working.

目前,这两个正则表达式似乎在做同样的事情:

At the moment, these two regexes seem to do the exact same thing:

对于非捕获组:(?:>) +(?:<)

没有非捕获组:>+<

我认为我对正则表达式的理解不够好,但我不确定.这里有什么问题吗?

I think my understanding of regex is not good enough, but I'm not sure. What's wrong here?

推荐答案

A 非捕获组 不捕获组中的子模式(您可以稍后参考),但是,所有在非捕获组中匹配的都不会从整个匹配结果中排除.

A non-capturing group doesn't capture the subpattern in a group (that you can refer later), however, all that have been matched in a non-capturing group is not excluded from the whole match result.

解决问题的方法是使用零宽度断言的lookarounds.环视只是测试,不是最终结果的一部分.

The way to solve the problem is to use lookarounds that are zero-width assertions. Lookarounds are only tests and are not part of the final result.

对于空格:

(?<=>) +(?=<)

对于所有空白字符:

(?<=>)\s+(?=<)

(另一种解决方案是使用 > +<>< 作为替换字符串)

(An other solution consists to use > +< with >< as replacement string)

这篇关于Sublime Text 中的非捕获组正则表达式不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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