Python语言基础
Python语言进阶
Python数据结构

检索字符串开头和结尾

检索字符串是否以【China】开头并以【country】结尾
以下实例为学习检索字符串是否以【China】开头并以【country】结尾,具体代码如下:
# Filename : example.py
# Author by : www.lidihuo.com
import re
txt = "China is a great country"
x = re.search("^China.*country$", txt)
if (x):
  print("YES! We have a match!")
else:
  print("No match")
执行以上代码输出结果为:
# Filename : example.py
# Author by : www.lidihuo.com

YES! We have a match!

昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4