python正则表达式-在re.sub之前删除空格
这是我的代码片段,这是基本的,我知道!我开始进入regex。当我运行下面的程序时,一切都正常,但我想知道如何缩小连字符和字符串替换之间的差距,例如,无论它在哪里表示一天的持续时间,例如,“八小时一天”现在改为“八小时一天”,我想关闭该空间。请帮忙python正则表达式-在re.sub之前删除空格,python,regex,string,Python,Regex,String,这是我的代码片段,这是基本的,我知道!我开始进入regex。当我运行下面的程序时,一切都正常,但我想知道如何缩小连字符和字符串替换之间的差距,例如,无论它在哪里表示一天的持续时间,例如,“八小时一天”现在改为“八小时一天”,我想关闭该空间。请帮忙 import re short_par = 'You must pace your work. What do I mean? I’m glad you asked that. We pace our work according to the ei
import re
short_par = 'You must pace your work. What do I mean? I’m glad you asked that. We pace our work according to the eight-hour workday. If you have twelve hours of work in your in-box, for example, you must compress that work into the eight-hour day. If you have one hour of work in your in-box, you must expand that work to fill the eight- hour day. That was a good question. Feel free to ask questions. Ask too many questions, however, and you may be let go.'
regex = re.compile('[hy]our')
print(regex.sub('BOOGIE', short_par))
您可以使用:
(?:(?请尊重SO社区并发布最简单的示例。不需要整个长短\u par
字符串来说明您的问题,但我们必须水平滚动它才能找到的“八小时”
place。我想你也可以使用re.sub
做你想做的。你应该能够找到答案。非常有帮助,谢谢大家的见解。
(?:(?<=-) )?[hy]our