Sublime Forum

[SOLVED] Regular extension - Search not include "\<"

#1

Hi all.
I have a noob question. In my document I need search and delete all scripts and links, but I have problem with regular extensions in sublimetext search.

Here is my two regexs what I using.
For scripts:
\<script[\s\S]*?\/script\>
For links
\<link\srel[\s\S]*?\>

Scripts are ± OK. In selections is content except “<>”, With links is that a problem because it seems ST3 not accept \<\> in selections. That mean, that I have in selections only “link rel” and not all content <link blablbabla>

I tried it on https://regex101.com/ and http://regexr.com/ and everyting is OK on these pages, but in sublimetext is that not work. Any idea for the solution are welcomes. Thank you for your time.

0 Likes

[Solved] View.find_all Doesn't Work With Certain Characters
#2

just remove the \ char before the < and the > and everything should work fine :wink:
these characters are not special and don’t need to be escaped
indeed, in Boost they have special meaning and are used as word boundaries - http://www.regular-expressions.info/wordboundaries.html#gnu

0 Likes

#3

Just as a side note, you can replace

[\s\S]*?

with

.*
0 Likes

#4

that would only work if there were no \n chars, as . doesn’t match newlines…

1 Like

#5

Huh. I did not know that. Thanks @kingkeith!

0 Likes

#6

But with [\s\s]*? is that not works. :confused:
On my ST3 works only if I delete first \ char. If I remove last \ char, that will not works. I can’t remove last \ char before > or I must replace [\s\s] to .*

Try it:

code:
<link rel="blablabla" href="blablabla">

search:
<link\srel[\s\s]*?>

0 Likes

#7

you’ve got lowercase \s twice now, change one to \S

side note: I’ve created a PR to the Default Packages repo which will make it easier to spot that \< isn’t an escaped (for no reason) <

1 Like

#8

Wops. My head is sh!t…x(

BTW how I can delete my spam topics like this? :smiley:

0 Likes

#9

I wouldn’t call it spam, at least 3 people learned something new about regular expressions, and an update to the syntax highlighting was proposed to prevent other people falling into the same trap :slight_smile:

2 Likes