官方正则表达式文档:re --- 正则表达式操作 — Python 3.10.6 文档
目的:获取字符串中的“第一天”
import re
def test1():
allStr = '第一天,今天是个好日子'
charter1 = re.search(r"第(.+?)天", allStr)
if charter1:
result = charter1.group().title()
print("打印:", result)
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
test1()
结果:
打印: 第一天