I would like to replace link texts using regex in sublime text 2
my links look like this
<a href="#" class="link link1">This is a text for link 1</a>
<a href="#" class="link link2">This is a text for link 2</a>
<a href="#" class="link link3">This is a text for link 3</a>
I have more than 100 links in my page.
I have tried regex like this.
<a href="#" class="link.+">.+</a>
It works But it match the tags too.
Can anyone tell me how to match only this text This is a text for link * ?
I don’t know why you only want to match the text, though. I can hardly think of any use case where that might be necessary. Usually capturing groups would be sufficient for most replacement scenarios.
If the text within the tag doesn’t have any pattern, and the tag can contain arbitrary classes, then NO, it is NOT possible to do so. SublimeText seems to use Boost library, which doesn’t support variable length look-behind.
If the tag are consistent (everything down to the spaces is the same), except for the link number in the
classattribute, then it might be possible to certain extent:If link followed by number class has 2 digits, you need to add in the corresponding look-behind:
(
\d{1,2}won’t work in look-behind. The length is not finitely many, but the regex engine doesn’t support it.)Working screenshot