5

I am using TeXStudio as my editor.

I encounter some difficulties in finding the regular expressions that can match strings occupying several lines.

For example, I need a regular expression that matches the patter $...$, namely anything (including line breaks) enclosed by two $'s.

I tried the regular expression \$[\s\S]*\$, but it only works when there is no line break between the two $'s. On the other hand, when I test this regular expression on the following website, this regular expression works for line breaks.

https://regexr.com/

I would like to know what is special about regular expressions in TeXStudio.

Zhiyuan Ding
  • 183
  • 8

1 Answers1

3

To answer your closing question: I don't think TeXStudio supports multi-line matching in the way you are describing. I can't seem to find a lot of documentation on its regex engine, but there is a lot of variation in regex implementation that leads to differences like this.

To help with the problem you are having: other editors do support multi-line matching like this - to varying degrees. If you want to just tag the instances like this and then edit them manually, Notepad++ has multi-line matching that will suffice. In my own experience with this issue, I needed to copy and paste out all of the matches in an efficient way - something Notepad++ cannot do, but Sublime Text can.

P.S. I think your regex should be \$[\s\S]*?\$ - with the added ? to make the * "lazy." Otherwise, I think it will keep matching until it runs out of $s to match on. Though, again, maybe that all depends on the regex implementation...

Mensch
  • 65,388
arwood
  • 46
  • This suggests that the problem is still open. \r\n or the like works in Notepad++. https://sourceforge.net/p/texstudio/discussion/907839/thread/5e78776f/ – Convexity Aug 26 '22 at 13:03