SublimeText / LaTeXTools

LaTeX plugin for Sublime Text
https://latextools.readthedocs.io/
2.01k stars 364 forks source link

Reverse Regex #1441

Closed Mq89 closed 4 years ago

Mq89 commented 4 years ago

I was wondering what could be the advantage of defining a regex in reverse as in the referenced file. Can anyone shed light to this?

https://github.com/SublimeText/LaTeXTools/blob/1d93810281464a81aff9272395b90ee78225a7f5/latex_cite_completions.py#L145-L171

r-stein commented 4 years ago

The reason ist quite simple: We want to match the text before the cursor. To do this we take the line before the cursor, reverse the text and the use re.match to match it. The alternative would be to write a regex like .*<the actual match>$, which would (most likely) perform slower, because it would match over the whole line and not just the end of the line.

Mq89 commented 4 years ago

Thank you.