Sublime Forum

How to increase regex bounds?

#1

Hello. Recently I used a complex regex (((.*\;)((\btext1\b)|(\btext2\b)|(\btext3\b)))(.*\n)(\2(.*)(\n)){1}) to find particular strings in a txt document (171 759 lines). Sublime said “The complexity of matching the regular expression exceeded predefined bounds.”. Is there a way to get around it?

0 Likes

#2

The short answer is to write better regular expressions, and I am saying that not be funny or snarky. Most likely you are triggering excessive back tracking. I would take a look at this http://www.regular-expressions.info/catastrophic.html.

If you can explain a bit better what you are trying to target and how you plan to use that info, someone may be able to help you construct a better regular expression.

0 Likes

#3

Is there a way to make it work?
I have this:

.*jid\[464\].*
0 Likes

#4

I’m not sure what your question is. Seems to work fine:

34%20PM

Okay?

1 Like

#5

Right, okay, apparently you don’t need extra pressure to pay attention to our issues :slight_smile: Sorry for that.

I will add more missing details. This is fedora32, v3.2.2, Build 3211.
The regexp does not work with 1Gb text (log) file. Fails straight away with the error as above. Apparently there is some blocker which got me on surprise. I don’t recon this limitation within Sublime 2.

0 Likes

#6

I’m just a dude who uses Sublime and sometimes answers questions, I’ll sleep like a baby tonight whether you uninstall Sublime or not :slightly_smiling_face:.

There may be some kind of search result limit. It wouldn’t surprise me if Sublime has sane limits for things to keep from gobbling up all memory and such. This may be a question for the Sublime devs though.

0 Likes

#7

Did you try using $ to anchor the regex at the end of a line so that Sublime doesn’t have to try and consider the entirety of a 1 gig file as part of the .* match?

0 Likes

#8

I don’t think it includes newlines by default does it? I honestly can’t recall right now and I’m not in front of my system.

0 Likes

#9

The . does not include newlines, that is correct. I will try $, but the fact that it stops depending on the size of the file sounds concerning.

0 Likes

#10

No, apparently not (well, not from the find panel anyway). Likely I was thinking of something I run into a fair bit using regex from the view API where I probably explicitly include \n.

0 Likes