在 Notepad++ 中查找并替换不在括号中的数字

Find and replace digits not in brackets in Notepad++

我有一个 Latex 文档,看起来像

Hello, my figure \ref{figure1} has an ecuation $e=mc^2$ with a mass of 10.5Kg or 20.5 Kg.

我想使用siunitx包,所以我的目标是将文本转换成

Hello, my figure \ref{figure1} has an ecuation $e=mc^2$ with a mass of \SI{10.5}{Kg} or \SI{20.5}{Kg}.

如何找到任何带或不带小数位的数字,后跟一个单词,中间有或没有空 space。仅查找不在 {} 或 $$ 之间的那些。用 \SI{digit found}{word after digit}

替换匹配项

任何建议都会有所帮助。理想情况下使用 notepad++ 但开放使用 Python、Sed...

怎么样:

查找内容:(?<!\{)(?<!$)\b(\d+(?:\.\d+)?)(?!=\})(?!=$)\s*([a-zA-Z]+)
替换为:\SI{}{}