【发布时间】:2019-04-11 20:21:56
【问题描述】:
我有以下字符串:
string = 'This is one sentence ${w_{1},..,w_{i}}$. This is another sentence. '
现在,我想把它分成两句话。
但是,当我这样做时:
string.split('.')
我明白了:
['This is one sentence ${w_{1},',
'',
',w_{i}}$',
' This is another sentence',
' ']
任何人都知道如何改进它,以免检测到“。”在$ $ 内?
另外,你会怎么做:
string2 = 'This is one sentence ${w_{1},..,w_{i}}$! This is another sentence. Is this a sentence? Maybe ! '
编辑 1:
期望的输出是:
对于字符串 1:
['This is one sentence ${w_{1},..,w_{i}}$','This is another sentence']
对于字符串 2:
['This is one sentence ${w_{1},..,w_{i}}$','This is another sentence', 'Is this a sentence', 'Maybe ! ']
【问题讨论】:
-
你想要的输出是什么?
-
您应该考虑的一件事是,在 LaTeX 中,正确的省略号是
\ldots,而不是...。 -
您将
.设置为分隔符,这就是为什么它会在找到的每个.处拆分您的字符串,而不管字符串中的上下文如何。 -
@ZevChonoles 是的,当然。我会改变的。但是,问题仍然存在,因为我还有其他情况,我不能简单地替换它。