Lacking reg-ex group in Sublime Text not working

enter image description here I am trying to remove all lingering spaces between tags. Therefore, I am trying to select them using regex.

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

My regular expression is (?:>) +(?:<) . I am trying to exclude > and < from the selection using a non-capture group, but it doesn't seem to work.

For now, these two regular expressions seem to do the same:

With non-exciting groups: (?:>) +(?:<)

Without non-capture groups: > +<

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

+6
source share
2 answers

A non-capture group does not capture the subpattern in the group (which you can reference later), however, everything that was agreed on in the group not participating in the capture is not excluded from the entire match result.

A way to solve the problem is to use lookarounds , which are zero-width statements. Lookarounds are tests only and are not part of the final result.

for spaces:

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

for all whitespace characters:

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

(Another solution is to use > +< c >< as a replacement)

+6
source

The purpose of non-capturing groups is to allow you to interact with the character set as a group without making it a send that you can use in the link. So you are right, (?:>) +(?:<) equivalent for your purposes > +< .

0
source

Source: https://habr.com/ru/post/971346/


All Articles