Search for (LaTeX) regex found NOT within another regex (math mode) -
i'm trying find improperly-written commands in latex not within math mode. is, in following, want match "\bad" not "\good\" or "\math".
example of \bad command. example of \good\ command. , $x=\math + y$ command.
i figured out how match math mode, begins , ends non-escaped dollar signs "$" -- want invert match somehow:
(?<!\\)\$.+?[^\\]\$
and figured out how match "\bad" not "\good\" (note space after +):
\\[a-za-z]+
but can't figure out how combine two. i've tried (negative) lookarounds , don't seem getting anywhere (not every paragraph contains math mode). suggestions/hints? in advance!
edit:
- i'm using perl-compatible regex (sublime text 3, exact).
- a "bad" command macro not within math mode, followed space. "good" command macro followed else -- punctuation or backslash -- or macro within math mode.
sublime text uses boost library handle regexes, it's not perl-compatible.
the true perl-compatible answer be:
\$.*?\$(*skip)(*fail)|\\\w+(?=\s)
but can't use (*skip)(*fail)
trick boost, unfortunately (until this feature request implemented).
you can work around somehow that:
\$.*?\$\k|\\\w+(?(?=\s)|\k)
the problem approach "bad" commands , math mode end markers still yield empty (zero-length) match (thanks \k
). don't know if that's enough you.
Comments
Post a Comment