当前位置: 首页 > news >正文

免费个人简历武汉久都seo

免费个人简历,武汉久都seo,玩具网站建设,南部县房产网目录 1. 不用正则表达式来查找文本模式2. 用正则表达式来查找文本模式2.1 创建正则表达式(Regex)对象2.2 匹配Regex对象 3. 用正则表达式匹配更多模式3.1 利用括号分组3.2 用管道匹配多个分组3.3 用问号实现可选匹配3.4 用星号匹配零次或多次3.5 用加号匹…

目录

  • 1. 不用正则表达式来查找文本模式
  • 2. 用正则表达式来查找文本模式
    • 2.1 创建正则表达式(Regex)对象
    • 2.2 匹配Regex对象
  • 3. 用正则表达式匹配更多模式
    • 3.1 利用括号分组
    • 3.2 用管道匹配多个分组
    • 3.3 用问号实现可选匹配
    • 3.4 用星号匹配零次或多次
    • 3.5 用加号匹配一次或多次
    • 3.6 用花括号匹配特定次数
  • 4. 贪心和非贪心匹配
  • 5. findall() 方法
  • 6. 字符分类
  • 7. 建立自己的字符分类
  • 8. 插入字符和美元字符
  • 9. 通配字符
    • 9.1 用点-星匹配所有字符
    • 9.2 用句点字符匹配换行符
  • 10. 不区分大小写的匹配
  • 11. 用 sub() 方法替换字符串

1. 不用正则表达式来查找文本模式

def isPhoneNumber(text):if len(text) != 11:return Falsefor i in range(0, len(text)):if (i == 3 or i == 7) and text[i] != "-":return Falseelif i != 3 and i != 7 and not text[i].isdecimal():return Falsereturn Truetext = "123-456-789"
print(text)
print(isPhoneNumber(text))

2. 用正则表达式来查找文本模式

2.1 创建正则表达式(Regex)对象

import retext = re.compile(r'\d\d\d-\d\d\d-\d\d\d')

2.2 匹配Regex对象

import retext = re.compile(r'\d\d\d-\d\d\d-\d\d\d')
match = text.search("~~~123-456-789~~~")
print(match.group())

3. 用正则表达式匹配更多模式

3.1 利用括号分组

import retext = re.compile(r'(\d\d\d)-(\d\d\d-\d\d\d)')
match = text.search("~~~123-456-789~~~")
print(match.group(1))
# 123
print(match.group(2))
# 456-789
print(match.groups())
# ('123', '456-789')

3.2 用管道匹配多个分组

  • | :管道
import retext = re.compile(r'456|123')
match = text.search("123-456-789")
print(match.group())
# 123

3.3 用问号实现可选匹配

import retext = re.compile(r'\d\d\d(~)?\d\d\d')
match = text.search("123123")
print(match.group())
# 123123match = text.search("123~123")
print(match.group())
# 123~123

3.4 用星号匹配零次或多次

import retext = re.compile(r'\d\d\d(~)*\d\d\d')
match = text.search("123123")
print(match.group())
# 123123match = text.search("123~~~123")
print(match.group())
# 123~~~123

3.5 用加号匹配一次或多次

import retext = re.compile(r'\d\d\d(~)+\d\d\d')
match = text.search("123~123")
print(match.group())
# 123~123match = text.search("123~~~123")
print(match.group())
# 123~~~123

3.6 用花括号匹配特定次数

import retext = re.compile(r'\d\d\d(~){3,5}\d\d\d')
match = text.search("123~~~123")
print(match.group())
# 123~~~123match = text.search("123~~~~~123")
print(match.group())
# 123~~~~~123

4. 贪心和非贪心匹配

  • 贪心匹配:尽可能匹配最长的字符串
  • 非贪心匹配:尽可能匹配最短的字符串
import retext = re.compile(r'(123 ){2,4}')
match = text.search("123 123 123 123 123 ")
print(match.group())
# 123 123 123 123text = re.compile(r'(123 ){2,4}?')
match = text.search("123 123 123 123 123 ")
print(match.group())
# 123 123

5. findall() 方法

import retext = re.compile(r'\d\d\d-\d\d\d-\d\d\d')
match = text.search("~~~123-456-789~~~111-222-333~~~")
print(match.group())
# 123-456-789match = text.findall("~~~123-456-789~~~111-222-333~~~")
print(match)
# ['123-456-789', '111-222-333']

6. 字符分类

编写字符分类表示
\d0~9的任何数字
\D除0~9的数字以外的任何字符
\w任何字母、数字和下划线字符
\W除字母、数字和下划线以外的任何字符
\s空格、制表符或换行符
\S除空格、制表符和换行符以外的任何字符

7. 建立自己的字符分类

import retext = re.compile(r'[0-5]')
match = text.findall("1a2b3c4d")
print(match)
# ['1', '2', '3', '4']text = re.compile(r'[abc]')
match = text.findall("1a2b3c4d")
print(match)
# ['a', 'b', 'c']text = re.compile(r'[^abc]')
match = text.findall("1a2b3c4d")
print(match)
# ['1', '2', '3', '4', 'd']

8. 插入字符和美元字符

  • ^ :以指定文本开始
  • $ :以指定文本结束
import retext = re.compile(r'^\d\d\d')
match = text.search("123abc456")
print(match)
# <re.Match object; span=(0, 3), match='123'>text = re.compile(r'\d\d\d$')
match = text.search("123abc456")
print(match)
# <re.Match object; span=(6, 9), match='456'>

9. 通配字符

  • . :匹配换行符之外的所有字符
import retext = re.compile(r'..23')
match = text.findall("123abc23")
print(match)
# ['bc23']

9.1 用点-星匹配所有字符

import retext = re.compile(r'123(.*)456(.*)')
match = text.findall("123abc456def")
print(match)
# [('abc', 'def')]

9.2 用句点字符匹配换行符

  • re.DOTALL :让句点字符匹配所有字符(包括换行符)
import retext = re.compile(r'.*')
match = text.search("123abc\n456def")
print(match.group())
# 123abctext = re.compile(r'.*', re.DOTALL)
match = text.search("123abc\n456def")
print(match.group())
# 123abc\n456def

10. 不区分大小写的匹配

  • re.I :不区分大小写
import retext = re.compile(r'abc', re.I)
match = text.findall("abcABC")
print(match)
# ['abc', 'ABC']

11. 用 sub() 方法替换字符串

import retext = re.compile(r'ABC\w*')
match = text.sub("abc", "ABC : 123")
print(match)
# abc : 123
http://www.ds6.com.cn/news/60963.html

相关文章:

  • 用tomcat做网站目录长沙百度搜索排名优化
  • 网站建设服务器端软件鹤壁网站推广公司
  • 网页设计实训总结结尾seo顾问咨询
  • 企业网站备案容易吗湖南seo优化服务
  • 第一次做网站选多大空间什么叫网络市场营销
  • 没有备案的网站百度不收录免费网络营销软件
  • 如何给网站加关键词怎么做营销
  • 广东省交通建设监理检测协会网站腾讯推广平台
  • 手机网站建设新闻网站注册账号
  • 电商网站建设分析搜索网排名
  • 怎么自己做网站的推广快速网站seo效果
  • 如何设置网站标题建站公司
  • 50万县城做地方网站百度seo推广方案
  • 自己做的网站怎么弄成appseo快速工具
  • 网站初期建设该做什么seo网络推广有哪些
  • 站酷网怎么样成都sem优化
  • 电子商务网站建设需要网站建设费用明细表
  • 甘肃网站开发企业seo是哪里
  • 中小企业网站制作平台软文广告范例大全
  • 网站推广外链怎么做游戏行业seo整站优化
  • 阿克苏网站怎么做seo创建网址快捷方式
  • 企业的网站用vue做的临沂seo公司
  • 北京关键词排名首页seo推广有哪些公司
  • 网站开发实施计划与安排青岛网站建设与设计制作
  • 网站 界面改版百度地图人工客服电话
  • 上海电子商务网站开发sem竞价托管代运营
  • 网站开发 方案 报价广东企业网站seo哪里好
  • 源码社区汉川seo推广
  • 网站首页背景代码百度识图搜索网页版
  • 网站建设联系我们网店推广渠道有哪些