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:

  1. i'm using perl-compatible regex (sublime text 3, exact).
  2. 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) 

demo

but can't use (*skip)(*fail) trick boost, unfortunately (until this feature request implemented).

you can work around somehow that:

\$.*?\$\k|\\\w+(?(?=\s)|\k) 

demo

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

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -