本系列文章是为 Python3 学习者精心设计的一套全面、实用的学习指南,旨在帮助读者从基础入门到项目实战,全面提升编程能力。文章结构由 5 个版块组成,内容层层递进,逻辑清晰。
无论你是 Python3 初学者,还是希望提升实战能力的开发者,本系列文章都能为你提供清晰的学习路径和实用的编程技巧,助你快速成长为 Python3 编程高手。
正则表达式(Regular Expression,简称 regex 或 regexp)是一种强大的工具,用于匹配和处理文本。Python 通过 re
模块提供了对正则表达式的支持。正则表达式可以用于搜索、替换、分割和验证字符串。
.
, *
, +
, ?
, ^
, $
, \
, |
, {
, }
, [
, ]
, (
, )
等。.
:匹配除换行符以外的任意单个字符。^
:匹配字符串的开头。$
:匹配字符串的结尾。*
:匹配前面的字符零次或多次。+
:匹配前面的字符一次或多次。?
:匹配前面的字符零次或一次。{n}
:匹配前面的字符恰好 n 次。{n,}
:匹配前面的字符至少 n 次。{n,m}
:匹配前面的字符至少 n 次,至多 m 次。\
:转义字符,用于匹配元字符本身。|
:或操作符,匹配左边或右边的表达式。[]
:字符集,匹配其中的任意一个字符。()
:分组,将多个字符作为一个整体进行匹配。\d
:匹配任意数字,等价于 [0-9]
。\D
:匹配任意非数字字符,等价于 [^0-9]
。\w
:匹配任意字母、数字或下划线,等价于 [a-zA-Z0-9_]
。\W
:匹配任意非字母、数字或下划线的字符,等价于 [^a-zA-Z0-9_]
。\s
:匹配任意空白字符,包括空格、制表符、换行符等。\S
:匹配任意非空白字符。re
模块常用函数re.match(pattern, string)
:从字符串的起始位置匹配正则表达式,如果匹配成功返回匹配对象,否则返回 None
。re.search(pattern, string)
:在字符串中搜索匹配正则表达式的第一个位置,如果匹配成功返回匹配对象,否则返回 None
。re.findall(pattern, string)
:返回字符串中所有匹配正则表达式的子串,返回一个列表。re.finditer(pattern, string)
:返回一个迭代器,包含所有匹配正则表达式的子串。re.sub(pattern, repl, string)
:将字符串中匹配正则表达式的部分替换为 repl
。re.split(pattern, string)
:根据正则表达式匹配的子串将字符串分割,返回一个列表。import re
text = "The price is 123.45 dollars."
pattern = r'\d+\.\d+'
match = re.search(pattern, text)
if match:
print("Found:", match.group())
import re
text = "Hello, world!"
pattern = r'world'
repl = 'Python'
new_text = re.sub(pattern, repl, text)
print(new_text) # 输出: Hello, Python!
import re
text = "apple,banana,cherry"
pattern = r','
result = re.split(pattern, text)
print(result) # 输出: ['apple', 'banana', 'cherry']
import re
text = "The rain in Spain falls mainly in the plain."
pattern = r'\bin\b'
matches = re.findall(pattern, text)
print(matches) # 输出: ['in', 'in', 'in']
分组使用 ()
来定义,可以捕获匹配的子串。
import re
text = "John Doe, Jane Doe"
pattern = r'(\w+) (\w+)'
matches = re.findall(pattern, text)
for first_name, last_name in matches:
print(f"First: {first_name}, Last: {last_name}")
默认情况下,*
和 +
是贪婪的,会尽可能多地匹配字符。可以在它们后面加上 ?
来使其变为非贪婪匹配。
import re
text = "Title "
pattern = r'<.*?>'
matches = re.findall(pattern, text)
print(matches) # 输出: ['', '', '', ' ', '', '']
如果需要多次使用同一个正则表达式,可以将其编译为正则表达式对象,以提高效率。
import re
pattern = re.compile(r'\d+')
text = "There are 3 apples and 5 oranges."
matches = pattern.findall(text)
print(matches) # 输出: ['3', '5']
re
模块提供了一些标志来修改正则表达式的行为,如忽略大小写、多行匹配等。
re.IGNORECASE
或 re.I
:忽略大小写。re.MULTILINE
或 re.M
:多行模式,^
和 $
匹配每行的开头和结尾。re.DOTALL
或 re.S
:使 .
匹配包括换行符在内的所有字符。import re
text = "Hello\nWorld"
pattern = r'^world'
match = re.search(pattern, text, re.IGNORECASE | re.MULTILINE)
if match:
print("Found:", match.group())
正则表达式是处理文本的强大工具,Python 的 re
模块提供了丰富的功能来支持正则表达式的使用。通过掌握正则表达式的基本语法和 re
模块的常用函数,你可以高效地处理各种文本匹配和替换任务。
以下是 10 个经典的正则表达式应用实例,每个实例都包含正则表达式的解释、测试代码以及执行结果的注释说明。
正则表达式: r'^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'
^
和 $
表示字符串的开始和结束。[a-zA-Z0-9_.+-]+
匹配用户名部分。@
匹配邮箱中的 @
符号。[a-zA-Z0-9-]+
匹配域名部分。\.
匹配域名中的点 .
。[a-zA-Z0-9-.]+
匹配顶级域名部分。import re
pattern = r'^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'
emails = ["[email protected]", "[email protected]", "invalid-email@com"]
for email in emails:
if re.match(pattern, email):
print(f"Valid: {email}")
else:
print(f"Invalid: {email}")
# 执行结果:
# Valid: [email protected]
# Valid: [email protected]
# Invalid: invalid-email@com
正则表达式: r'^1[3-9]\d{9}$'
1
表示手机号码的第一位。[3-9]
表示第二位可以是 3 到 9 之间的数字。\d{9}
表示后面跟着 9 位数字。import re
pattern = r'^1[3-9]\d{9}$'
phones = ["13800138000", "12345678901", "19912345678"]
for phone in phones:
if re.match(pattern, phone):
print(f"Valid: {phone}")
else:
print(f"Invalid: {phone}")
# 执行结果:
# Valid: 13800138000
# Invalid: 12345678901
# Valid: 19912345678
正则表达式: r'https?://(?:www\.)?\S+'
https?
匹配 http
或 https
。://
匹配 URL 中的协议分隔符。(?:www\.)?
匹配可选的 www.
。\S+
匹配 URL 的其余部分。import re
pattern = r'https?://(?:www\.)?\S+'
urls = ["https://www.example.com", "http://example.com", "ftp://example.com"]
for url in urls:
if re.match(pattern, url):
print(f"Valid: {url}")
else:
print(f"Invalid: {url}")
# 执行结果:
# Valid: https://www.example.com
# Valid: http://example.com
# Invalid: ftp://example.com
正则表达式: r'^\d{4}-[01]?[0-2]-[0123]?[0-9]$'
YYYY-MM-DD
格式的日期。\d{4}
匹配 4 位年份。-
匹配日期分隔符。[01]?[0-2]
匹配 2 位月份。[0123]?[0-9]
匹配 2 位日期。import re
pattern = r'^\d{4}-[01]?[0-2]-[0123]?[0-9]$'
dates = ["2023-10-05", "2023/10/05", "2023-13-01"]
for date in dates:
if re.match(pattern, date):
print(f"Valid: {date}")
else:
print(f"Invalid: {date}")
# 执行结果:
# Valid: 2023-10-05
# Invalid: 2023/10/05
# Invalid: 2023-13-01
正则表达式: r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$'
\d{1,3}
匹配 1 到 3 位数字。\.
匹配 IP 地址中的点 .
。import re
pattern = r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$'
ips = ["192.168.1.1", "256.256.256,256", "127.0.0.1"]
for ip in ips:
if re.match(pattern, ip):
print(f"Valid: {ip}")
else:
print(f"Invalid: {ip}")
# 执行结果:
# Valid: 192.168.1.1
# Invalid: 256.256.256.256
# Valid: 127.0.0.1
正则表达式: r'<(\w+)[^>]*>(.*?)\1>'
<(\w+)
匹配标签名。[^>]*
匹配标签内的属性。>(.*?)
匹配标签内容。\1>
匹配对应的闭合标签。import re
pattern = r'<(\w+)[^>]*>(.*?)\1>'
html = "Hello World"
match = re.search(pattern, html)
if match:
print(f"Tag: {match.group(1)}, Content: {match.group(2)}")
# 执行结果:
# Tag: div, Content: Hello World
正则表达式: r'[\u4e00-\u9fff]+'
[\u4e00-\u9fff]
是中文字符的 Unicode 范围。import re
pattern = r'[\u4e00-\u9fff]+'
text = "Hello 世界"
matches = re.findall(pattern, text)
print(matches) # 执行结果: ['世界']
正则表达式: r'^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[\W_]).{8,}$'
(?=.*[A-Z])
确保至少有一个大写字母。(?=.*[a-z])
确保至少有一个小写字母。(?=.*\d)
确保至少有一个数字。(?=.*[\W_])
确保至少有一个特殊字符。.{8,}
确保密码长度至少为 8。import re
pattern = r'^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[\W_]).{8,}$'
passwords = ["Password123!", "weakpass", "StrongPass1"]
for pwd in passwords:
if re.match(pattern, pwd):
print(f"Strong: {pwd}")
else:
print(f"Weak: {pwd}")
# 执行结果:
# Strong: Password123!
# Weak: weakpass
# Strong: StrongPass1
正则表达式: r'^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$'
#FFFFFF
或 #FFF
)。#
匹配颜色值开头的 #
。[A-Fa-f0-9]{6}
匹配 6 位十六进制值。[A-Fa-f0-9]{3}
匹配 3 位十六进制值。import re
pattern = r'^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$'
colors = ["#FFFFFF", "#FFF", "#123456", "#GHIJKL"]
for color in colors:
if re.match(pattern, color):
print(f"Valid: {color}")
else:
print(f"Invalid: {color}")
# 执行结果:
# Valid: #FFFFFF
# Valid: #FFF
# Valid: #123456
# Invalid: #GHIJKL
正则表达式: r'^(\w+)\.(\w+)$'
(\w+)
匹配文件名。\.
匹配点 .
。(\w+)
匹配扩展名。import re
pattern = r'^(\w+)\.(\w+)$'
filename = "example.txt"
match = re.match(pattern, filename)
if match:
print(f"Filename: {match.group(1)}, Extension: {match.group(2)}")
# 执行结果:
# Filename: example, Extension: txt
在使用正则表达式时,初学者和中级用户经常会遇到一些常见错误。以下是 10 种常见的正则表达式错误、原因分析以及纠错方法。
错误:直接使用 .
、*
、+
等元字符而未转义。
import re
pattern = r'example.com'
text = "example-com"
match = re.search(pattern, text) # 无法匹配
原因:.
是元字符,匹配任意字符,而不是字面的点 .
。
纠错:使用 \.
转义。
pattern = r'example\.com'
错误:使用 .*
或 .+
时匹配过多内容。
import re
pattern = r'<.*>'
text = "HelloWorld
"
match = re.search(pattern, text) # 匹配整个字符串
原因:*
和 +
是贪婪的,会尽可能多地匹配字符。
纠错:使用非贪婪匹配 .*?
或 .+?
。
pattern = r'<.*?>'
错误:在多行文本中使用 ^
或 $
时,未启用多行模式。
import re
pattern = r'^Hello'
text = "Line1\nHello\nLine2"
match = re.search(pattern, text) # 无法匹配
原因:默认情况下,^
和 $
只匹配字符串的开头和结尾。
纠错:使用 re.MULTILINE
标志。
match = re.search(pattern, text, re.MULTILINE)
错误:在字符集中未正确使用 -
。
import re
pattern = r'[A-Z]'
text = "abc123"
match = re.search(pattern, text) # 无法匹配小写字母
原因:[A-Z]
只匹配大写字母。
纠错:使用 [A-Za-z]
匹配所有字母。
pattern = r'[A-Za-z]'
错误:未正确使用分组捕获。
import re
pattern = r'(\d{2})-(\d{2})-(\d{4})'
text = "12-31-2023"
match = re.search(pattern, text)
if match:
print(match.group(1)) # 输出 12
原因:分组索引从 1 开始,group(0)
是整个匹配内容。
纠错:确保使用正确的分组索引。
if match:
print(match.group(1), match.group(2), match.group(3)) # 输出 12 31 2023
错误:未忽略大小写导致匹配失败。
import re
pattern = r'hello'
text = "Hello World"
match = re.search(pattern, text) # 无法匹配
原因:默认情况下,正则表达式区分大小写。
纠错:使用 re.IGNORECASE
标志。
match = re.search(pattern, text, re.IGNORECASE)
错误:量词使用不当导致匹配失败。
import re
pattern = r'\d{3,5}'
text = "123"
match = re.search(pattern, text) # 匹配成功,但可能不符合预期
原因:{3,5}
表示匹配 3 到 5 个数字,但可能匹配过多。
纠错:根据需求调整量词。
pattern = r'\d{3}' # 只匹配 3 个数字
错误:未使用单词边界 \b
。
import re
pattern = r'cat'
text = "category"
match = re.search(pattern, text) # 匹配成功,但可能不符合预期
原因:cat
会匹配 category
中的 cat
。
纠错:使用 \b
确保匹配完整单词。
pattern = r'\bcat\b'
错误:未正确处理空白字符。
import re
pattern = r'hello world'
text = "hello world"
match = re.search(pattern, text) # 无法匹配
原因:正则表达式中的空格是字面匹配。
纠错:使用 \s+
匹配空白字符。
pattern = r'hello\s+world'
错误:未正确处理多行文本中的换行符。
import re
pattern = r'^Hello'
text = "Line1\nHello\nLine2"
match = re.search(pattern, text) # 无法匹配
原因:不能正确处理换行符。
纠错:使用 re.MULTILINE
标志。
match = re.search(pattern, text, re.MULTILINE)
正则表达式虽然强大,但在使用时容易犯一些常见错误。通过理解这些错误的原因并掌握纠错方法,可以更高效地使用正则表达式处理文本。
这是一份关于“正则表达式”的测试试卷。包含:选择题:15 道、填空题:10 道和 编程题:5 道,总分 100 分。每道题后附有答案和解析。
以下哪个正则表达式可以匹配任意数字?
\d
\D
\w
\s
\d
匹配任意数字,\D
匹配非数字,\w
匹配字母、数字或下划线,\s
匹配空白字符。以下哪个正则表达式可以匹配一个或多个字母?
[a-z]
[a-z]+
[a-z]*
[a-z]?
+
表示前面的字符至少出现一次。以下哪个正则表达式可以匹配字符串的开头?
$
^
\b
\B
^
匹配字符串的开头,$
匹配字符串的结尾。以下哪个正则表达式可以匹配一个单词边界?
\b
\B
^
$
\b
匹配单词边界,\B
匹配非单词边界。以下哪个正则表达式可以匹配一个浮点数?
\d+\.\d+
\d*\.\d*
\d+\.\d*
\d*\.\d+
\d+\.\d+
匹配至少一个数字,后跟一个小数点,再跟至少一个数字。以下哪个正则表达式可以匹配一个邮箱地址?
[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-zA-Z]+
[a-zA-Z0-9]+@[a-zA-Z0-9]+
[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-zA-Z0-9]+
[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-zA-Z0-9]+\.
用户名@域名.顶级域名
。以下哪个正则表达式可以匹配一个 URL?
https?://\S+
http://\S+
https://\S+
http://\S
https?
匹配 http
或 https
,\S+
匹配非空白字符。以下哪个正则表达式可以匹配一个 HTML 标签?
<.*>
<.*?>
<.+>
<.+?>
<.*?>
使用非贪婪匹配,避免匹配过多内容。以下哪个正则表达式可以匹配一个中文字符?
[\u4e00-\u9fff]
[a-zA-Z]
\d
\w
[\u4e00-\u9fff]
是中文字符的 Unicode 范围。以下哪个正则表达式可以匹配一个 IP 地址?
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}
\d{1,3}\.\d{1,3}\.\d{1,3}
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}
.
分隔。以下哪个正则表达式可以匹配一个日期(YYYY-MM-DD)?
\d{4}-\d{2}-\d{2}
\d{2}-\d{2}-\d{4}
\d{4}/\d{2}/\d{2}
\d{2}/\d{2}/\d{4}
\d{4}-\d{2}-\d{2}
匹配 YYYY-MM-DD
格式的日期。以下哪个正则表达式可以匹配一个时间(HH:MM:SS)?
\d{2}:\d{2}:\d{2}
\d{2}:\d{2}
\d{2}:\d{2}:\d{2}:\d{2}
\d{2}:\d{2}:\d{2}:\d{2}:\d{2}
\d{2}:\d{2}:\d{2}
匹配 HH:MM:SS
格式的时间。以下哪个正则表达式可以匹配一个十六进制颜色值?
#[A-Fa-f0-9]{6}
#[A-Fa-f0-9]{3}
#[A-Fa-f0-9]{6}|#[A-Fa-f0-9]{3}
#[A-Fa-f0-9]{6}|#[A-Fa-f0-9]{3}|#[A-Fa-f0-9]{2}
以下哪个正则表达式可以匹配一个文件名和扩展名?
\w+\.\w+
\w+\.\w
\w+\.\w{2,4}
\w+\.\w+\.\w+
\w+\.\w+
匹配文件名和扩展名。以下哪个正则表达式可以匹配一个强密码(至少 8 位,包含大小写字母、数字和特殊字符)?
^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[\W_]).{8,}$
^(?=.*[A-Z])(?=.*[a-z])(?=.*\d).{8,}$
^(?=.*[A-Z])(?=.*[a-z]).{8,}$
^(?=.*[A-Z])(?=.*\d).{8,}$
(?=.*[A-Z])
确保至少有一个大写字母,(?=.*[a-z])
确保至少有一个小写字母,(?=.*\d)
确保至少有一个数字,(?=.*[\W_])
确保至少有一个特殊字符。正则表达式 \d{3}-\d{2}-\d{4}
可以匹配的格式是:________。
答案:XXX-XX-XXXX
(例如:123-45-6789)
正则表达式 ^[A-Za-z]+$
可以匹配的字符串是:________。
答案:仅包含字母的字符串
正则表达式 \b\w+\b
可以匹配的字符串是:________。
答案:一个完整的单词
正则表达式 \d{2}:\d{2}:\d{2}
可以匹配的格式是:________。
答案:HH:MM:SS
(例如:12:34:56)
正则表达式 [\u4e00-\u9fff]+
可以匹配的字符串是:________。
答案:中文字符
正则表达式 ^[a-zA-Z0-9_]{4,16}$
可以匹配的字符串是:________。
答案:4 到 16 位的用户名(字母、数字、下划线)
正则表达式 https?://\S+
可以匹配的字符串是:________。
答案:HTTP 或 HTTPS 协议的 URL
正则表达式 \d+\.\d+
可以匹配的字符串是:________。
答案:浮点数(例如:3.14)
正则表达式 ^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$
可以匹配的字符串是:________。
答案:十六进制颜色值(例如:#FFFFFF 或 #FFF)
正则表达式 ^(\d{4})-(\d{2})-(\d{2})$
可以匹配的格式是:________。
答案:YYYY-MM-DD
(例如:2023-10-05)
编写一个正则表达式,匹配一个合法的邮箱地址。
答案:
import re
pattern = r'^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'
emails = ["[email protected]", "invalid-email@com"]
for email in emails:
if re.match(pattern, email):
print(f"Valid: {email}")
else:
print(f"Invalid: {email}")
编写一个正则表达式,匹配一个合法的手机号码(中国大陆)。
答案:
import re
pattern = r'^1[3-9]\d{9}$'
phones = ["13800138000", "12345678901"]
for phone in phones:
if re.match(pattern, phone):
print(f"Valid: {phone}")
else:
print(f"Invalid: {phone}")
编写一个正则表达式,匹配一个合法的 URL。
答案:
import re
pattern = r'https?://(?:www\.)?\S+'
urls = ["https://www.example.com", "ftp://example.com"]
for url in urls:
if re.match(pattern, url):
print(f"Valid: {url}")
else:
print(f"Invalid: {url}")
编写一个正则表达式,匹配一个合法的日期(YYYY-MM-DD)。
答案:
import re
pattern = r'^\d{4}-\d{2}-\d{2}$'
dates = ["2023-10-05", "2023/10/05"]
for date in dates:
if re.match(pattern, date):
print(f"Valid: {date}")
else:
print(f"Invalid: {date}")
编写一个正则表达式,匹配一个合法的强密码(至少 8 位,包含大小写字母、数字和特殊字符)。
答案:
import re
pattern = r'^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[\W_]).{8,}$'
passwords = ["Password123!", "weakpass"]
for pwd in passwords:
if re.match(pattern, pwd):
print(f"Strong: {pwd}")
else:
print(f"Weak: {pwd}")
本节内容包含 3 个关于“正则表达式”的综合应用项目,每个项目都包含完整的程序代码、测试案例、执行结果以及代码说明。具体项目是:
从一段文本中提取所有合法的邮箱地址。
import re
def extract_emails(text):
# 正则表达式匹配邮箱地址
pattern = r'[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+'
# 查找所有匹配的邮箱地址
emails = re.findall(pattern, text)
return emails
# 测试案例
text = """
Contact us at [email protected] or [email protected].
For more information, visit https://www.example.com.
Invalid email: user@com.
"""
emails = extract_emails(text)
print("Extracted emails:", emails)
Extracted emails: ['[email protected]', '[email protected]']
[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+
匹配邮箱地址。re.findall
返回所有匹配的邮箱地址。从日志文件中提取所有错误日志(包含 “ERROR” 关键字)。
import re
def extract_errors(log_file):
# 正则表达式匹配错误日志
pattern = r'ERROR.*'
errors = []
with open(log_file, 'r') as file:
for line in file:
match = re.search(pattern, line)
if match:
errors.append(match.group())
return errors
# 测试案例
log_file = 'sample_log.txt'
# 假设 sample_log.txt 内容如下:
"""
INFO: User logged in
ERROR: Failed to connect to database
INFO: Request processed
ERROR: File not found
"""
errors = extract_errors(log_file)
print("Error logs:")
for error in errors:
print(error)
Error logs:
ERROR: Failed to connect to database
ERROR: File not found
ERROR.*
匹配以 “ERROR” 开头的日志行。从 HTML 文本中提取所有标签及其内容。
import re
def extract_html_tags(html):
# 正则表达式匹配 HTML 标签及其内容
pattern = r'<(\w+)[^>]*>(.*?)\1>'
tags = re.findall(pattern, html)
return tags
# 测试案例
html = """
Welcome
This is a test paragraph.
Link
"""
tags = extract_html_tags(html)
print("HTML tags and content:")
for tag, content in tags:
print(f"Tag: {tag}, Content: {content}")
HTML tags and content:
Tag: div, Content: Welcome
Tag: p, Content: This is a test paragraph.
Tag: a, Content: Link
<(\w+)[^>]*>(.*?)\1>
匹配 HTML 标签及其内容。re.findall
返回所有匹配的标签及其内容。以上 3 个迷你项目展示了正则表达式在实际应用中的强大功能,包括文本提取、日志分析、HTML 处理等。通过这些项目,可以更好地理解和掌握正则表达式的使用。