要提取出现在字符串r中的工作日,可以使用正则表达式和字符串处理方法来实现。以下是一个可能的解决方案:
import re
pattern = r"(Monday|Tuesday|Wednesday|Thursday|Friday)"
result = re.findall(pattern, r)
print(result)
完整的代码如下:
import re
def extract_weekdays(r):
pattern = r"(Monday|Tuesday|Wednesday|Thursday|Friday)"
result = re.findall(pattern, r)
return result
r = "Today is Monday. Tomorrow is Tuesday."
weekdays = extract_weekdays(r)
print(weekdays)
该代码将输出:['Monday', 'Tuesday']
注意:上述代码仅提供了一个示例解决方案,你可以根据实际情况进行适当修改和优化。
领取专属 10元无门槛券
手把手带您无忧上云