【发布时间】:2019-06-11 18:19:57
【问题描述】:
这里_also是可选的,如何拆分字符串使_also成为可选?
>>> aa="may_be_this.is_the_string"
>>> aa.split('this.')[1]
'is_the_string'
>>>
>>> aa="may_be_this_also.is_the_string"
>>> aa.split('this[_also]*.')[1] # something like this, to make _also as optional substring.
【问题讨论】:
-
"may_be_this_also_also.is_the_string"会如何运作? (两个 _also's) -
'this[_also]*.'将从'textlike_this_____aaaalllssooooooJuhu'拆分为['text','uhu']- 这应该会发生吗? -
"may_be_this_also.is_the_string"的预期输出是什么? -
@DeveshKumarSingh,
is_the_string -
好的,评论者指出的其他输出呢?比如
"may_be_this_also_also.is_the_string"和'textlike_this_____aaaalllssooooooJuhu'
标签: python regex python-3.x python-3.6