手把手带你学python—牛客网python基础第三期正则表达式详解

发布于:2023-01-17 ⋅ 阅读:(452) ⋅ 点赞:(0)

牛客是一款不论是面试 还是刷题 都是非常有用的 还等什么,传送门- 牛客网python基础

🥇作者简介:大家好我是 uu 给刚入门的python的小伙伴带来一套python 完整的入门基础。

🥈个人主页:uu主页

📑 推荐一款非常火的面试、刷题神器👉  牛客网python基础

觉得uu写的不错的话 麻烦动动小手 点赞👍 收藏⭐  评论📄

今天给大家带来的刷题系列是:正则表达式详解

                              

                              
 

w="qwegvywteilkajgmyqw[e'a;dkgl,/qewwatfet1]"
b=re.findall(r'e(.*?)1',w)
v=re.findall(r'a.*?ww',w)
print(b)
print(v)

a="23rfgg34王35哈哈发34-533.404傻逼10.0"
c= re.findall(r"-?\d+\.?\d*e??\d*?",a)
print(c)
d= re.findall('[\u4E00-\u9FA5\\s]',a)
print(d)
e= re.findall('\d+',a)
print(e)
r=re.findall('-\d+\.?\d*e??\d*?',a)
print(r)
o=re.findall('\d+',a)
print(o)

 

 

 

提取字符串中所有的实数 

import re
 
a = "23rfgg3.4王0.55发-5.498 s62.36逼0.000-0.6+6"
 
# 提取所有的实数
b = re.findall(r"-?\d+\.?\d*e??\d*?", a)
print(b)

提取所有汉字 

# 提取所有的汉字
d = re.findall('[\u4E00-\u9FA5\\s]', a)
print(d)

 前边一个空格 后边一个空格就是只匹配这个单词to 不加空格 就是匹配所有的to这个字符串

peom="App Please send this message ato a23 A-、a-- Aa- AOO Aoo wert thtose people awhto mean something to you,to those who have touched your life in one way or another,to those who make you smile when you really need it,to those that make you see the brighter side of things when you are really down,to those who you want to let them know that you appreciate their friendship.And if you don’t, don’t worry,nothing bad will happen to you,you will just miss out on the opportunity to brighten someone’s day with this message"


### 前边一个空格 后边一个空格就是只匹配这个单词to 不加空格 就是匹配所有的to这个字符串

find_to=re.findall(" to ",peom)
print(find_to)

 [a-z] 表示匹配一个字母  普通的一个点. 可以匹配任何东西 # 查看是以a开头 且三个字母的单词 

a=re.findall("a.. ",peom)
print(a)

只匹配字母三个字母的 左右加上空格之后 只匹配a开头 的三个字母的单独的单词

a=re.findall(" a[a-z][a-z] ",peom) #
print(a)

只匹配字母且三个字母的 左右加上空格之后 ,只匹配a开头的三个字母的单独的单词, 加上括号之后就表示只要括号里面的其他的不要相比于上边没有了 空格输出

a=re.findall(" (a[a-z][a-z]) ",peom)
print(a)

匹配两个字母或者是三个字母

a=re.findall("\w{2,3}",ss)
print(a)

牛客是一款不论是面试 还是刷题 都是非常有用的 还等什么,传送门- 牛客网python基础

                              

本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到