SublimeText / WordHighlight

Highlight all copies of the currently selected word.
MIT License
179 stars 24 forks source link

Improving the regular expression #23

Open titoBouzout opened 12 years ago

titoBouzout commented 12 years ago

Most of the execution time of this package is on the call view.find_all or view.find which uses a regular expression to search for the words, returning the regions used.

Currently the regular expression is :

'(?<![\\w])'+re.escape(string)+'\\b'

Can you thing on a way to improve it? There is also situations on which this expression raises:

RuntimeError: The complexity of matching the regular expression exceeded predefined bounds.  Try refactoring the regular expression to make each choice made by the state machine unambiguous.  This exception is thrown to prevent "eternal" matches that take an indefinite
adzenith commented 12 years ago

It seems like a pretty straightforward regex... I'm not sure why the error talks about its complexity, unless we're running it when there's a huge selection or something. There's no branching or anything, so I'm not sure how we could dial it in.

cpagravel commented 9 years ago

I get the same thing: ^(\s+)+((?:if|foreach|while) (.*)) ([a-z]|\$)

adzenith commented 9 years ago

@chrisgravel did you get that error while running WordHighlight, or just while searching?

cpagravel commented 9 years ago

I got it just while searching. I realize now that my comment is invalid, I thought this was for Sublime Text dev, not one of the plugins.