我想知道是否有任何方法可以组合模式re.sub()而不是使用倍数,如下所示:
import re
s1 = "Please check with the store to confirm holiday hours."
s2 = ''' Hours:
Monday: 9:30am - 6:00pm
Tuesday: 9:30am - 6:00pm
Wednesday: 9:30am - 6:00pm
Thursday: 9:30am - 6:00pm
Friday: 9:30am - 9:00pm
Saturday: 9:30am - 6:00pm
Sunday: 11:00am - 6:00pm
Please check with the store to confirm holiday hours.'''
strip1 = re.sub(s1, '', s2)
strip2 = re.sub('\t', '', strip1)
print(strip2)
Run Code Online (Sandbox Code Playgroud)
期望的输出:
Hours:
Monday: 9:30am - 6:00pm
Tuesday: 9:30am - 6:00pm
Wednesday: 9:30am …Run Code Online (Sandbox Code Playgroud)