异常改变大小写特别是在美元符号之间

Changing Case with Exception Specifically in between dollar signs

输入:

MECR-tree obtained using \textbf{MCAR-Miner} with $S_{\mathrm{U}}  = data$ 25{\%} and $S_{\mathrm{L}}  = string$ 12.5{\%}

将其更改为 Title Case 但免除 $ 符号内的文本。

输出应该是:

Mecr-Tree Obtained Using \textbf{Mcar-Miner} With $S_{\mathrm{U}}  = data$ 25{\%} And $S_{\mathrm{L}}  = string$ 12.5{\%}

这是一个假设 $ 字符总是成对出现的例子:

sp = s.split('$')
for i, seg in enumerate(sp):
    if i % 2 == 0:
        sp[i] = seg.title()

print('$'.join(sp))

使用列表理解:

print(r'$'.join([seg.title() if not i % 2 else seg for i, seg in enumerate(s.split('$'))]))