>>> text="hi, my name is angle enrico, how is everything going?"
>>> pre = text[text.index("hi, my name is ")+len("hi, my name is "):]
>>> pre
'angle enrico, how is everything going?'
>>> suf = pre[pre.index(", ")+len(", "):]
>>> suf
'how is everything going?'
看起来您正在尝试在非regex上下文中使用regex语法。您的代码当前所做的是搜索文本字符串
hi, my name is\s+
,它显然不存在于您的输入字符串中。你知道吗您需要做的是编写一个正则表达式来捕获字符串的开头,然后将其传递到
text.replace
。你知道吗尝试使用:
或:
两者都繁殖:
相关问题 更多 >
编程相关推荐