Cats are smarter than dogs.
这句话用正则表达式改变为 Dogs are smarter than cats. 注意大小写
import re
text="Cats are smarter than dogs."
先转换成小写,将首尾互换,再将首字母改成大写,但是不会写相关的正则表达式
Cats are smarter than dogs.
这句话用正则表达式改变为 Dogs are smarter than cats. 注意大小写
这个意思?
import re
s = "Cats are smarter than dogs."
res = re.findall("^(.*?) (.*) (.*?)\.$", s)[0]
s1 = f"{res[2].title()} {res[1]} {res[0].lower()}."
print(s1)