I just started using UltiSnips for Vim and now I'm trying out transformations. I can't wrap my head around one of the first examples given in the screencast. The transformation is for an HTML tag to drop everything but the tag name for the closing tag. The relevant part of the snippet is given below
<$1>
</${1/(\w+).*/$1/}>
No matter how I look at it, what I get from this regex is that it is saying "Match a full word, and then all the characters after that. I tried it out using RegExr, and my assumption was correct. If given a text "div class="
the above regex matches the entire text.
I tried it out on python as well (since Ultisnips uses the python re module).
a = re.search('(\w+).*/$1/)
will give me the entire string in a.group()
. It will also give me (0,10)
as the answer for a.span()
. Yet UltiSnips takes $1 to be just div.
Am I thinking about this the wrong way? How exactly is this working?
After trying the regex out on regex101.com, I get div as match group #1. I also get div as the only match if I use (\w+)
instead of (\w+).*
. But when I try to use
</${1/(\w+)/$1/}>
as the transformation syntax, the entire string that I type in (div class=
) gets included. Basically it matches the whole string.