Products
GG网络技术分享 2025-03-18 16:14 0
Cats are smarter than dogs.
这句话用正则表达式改变为 Dogs are smarter than cats. 注意大小写
import retext="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)
正则表达式是一种文本模式,用于搜索匹配文本中的一个或多个字符串。
Python 提供名为 re 的内置包,可用于处理正则表达式。
匹配字符串的开始,如果匹配成功,则返回match对象。没有匹配,则返回none。
格式:match(<正则表达式>,<字符串>)
Demand feedback