Lazy loaded image
🐍Python 教程
Python常用库之Re(Regular Expression)
Words 706Read Time 2 min
2024-10-28
2024-11-29
type
date
slug
category
icon
password

直观全流程的正则表达式教程

用 Python 和正则表达式抽取文本结构化信息 - 少数派

Interactive Practice and self-check websites

RegexOne—Learn Regular Expressions with simple, interactive exercises.

notion image

生成检查正则表达式

Practice01-Matching Numbers

Practice02-Matching Phone Numbers

 
notion image

practice03-Matching Emails

notion image
practice04-Matching HTML
notion image

practice05-Extracting Data FRom URLs

notion image

practice06-Matching Specific filenames

notion image

practice07-Matching Lines

 
notion image

practice08-

notion image

Re Module

  1. re.search()
For data analysis, the emphasis is the existence of a specified period of characteristics
2. re.match() Validation 从首字母就开始匹配, 和^...$作用类似
Graphical interfere will accept input info and match data stored in the repoistory
3. findall() if succeed ,return list, if not nreturn none
4. finditer() return callable_iterator object if succeed
5. re.split()
re.split(pat,str,maxspliy=0,flag=0)
6. re.sub()
re.sub(pat,repl,string,count=0,flags=0)
 
7. Compile Regula Expression re.compile(pat,flags=0)
 
notion image
 

Compile Flag(编译标志)

  1. Ascll 表和Unicode
2. Case-insensitive
3. 点(.)匹配换行符以外的所有字符
4. 多行模式,任意一行的开始或者结束匹配就行
5. 详细模式,可以以注释的方式写正则表达式,便于阅读

Practical Project

 
 
 
 

Reference

 
上一篇
Python常用库之cython
下一篇
基于 Python 面相对象开发

Comments
Loading...