Home Download Buy Blog Forum Support

regular expression problem?

regular expression problem?

Postby mikeonbike on Wed Mar 14, 2012 9:43 am

Hi! Sublime won't find my regexp when i'm using \s and puts error. Is it bug or wrong regexp?
sublime_regexp.jpg (205.19 KiB) Viewed 3266 times

for tests i'm using that text:

Code: Select all
  <div id="crumbs">
                            <a href="<!--#echo var="basic_url_ssl" -->inside/index.shtml">Главная</a>
Posts: 1
Joined: Wed Mar 14, 2012 9:36 am

regular expression problem with match multi line new line

Postby Jim on Wed Mar 14, 2012 10:44 am

I am still have to find my way on sublime regex implementation, but try

(?s)<div id="crumbs">(.+?)</div>

I hope i explain it right:
(?s) => take expression as single line search ( means: the dot should match \n too)
(.+?) => match one-or-more of any sign, but be non-greedy to stop at first found "</div>"

In my testings last weeks i had different results i think, but this works for me for your examples on 2181.
Jim (Win32 v7, ST3)
Posts: 41
Joined: Sun Feb 26, 2012 5:21 pm

Re: regular expression problem?

Postby pete340 on Wed Mar 14, 2012 11:39 am

mikeonbike wrote:Hi! Sublime won't find my regexp when i'm using \s and puts error. Is it bug or wrong regexp?

(\s.*)* is really nasty to evaluate. The error message basically says that the effort to evaluate it was too complicated. Think through what this is asking for: any combination of space characters followed by any combination of characters, repeated as many times as needed. So if the text being searched is a single space character, all is well. There's exactly one way to match it. If the text is two space characters, the match could be: \s matches both spaces, .* matches nothing, ()* matches exactly once; \s matches first space, .* matches second space, ()* matches exactly once; \s matches one space, .* matches nothing, ()* matches twice. So there are three possible matches. Now try three space characters and see how fast the number of possible matches blows up. My guess is that there are about 20 ways to match. And as you add more characters to the string to be matched, the number of possible matches becomes astronomical. Sublime gave up in despair.

What part of the text are you trying to pick out?
Posts: 96
Joined: Mon Oct 10, 2011 9:45 pm

Return to Technical Support

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 27 guests