Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

python re.findall

作者:_永恒灬莫言   发布日期:2025-05-01   浏览:105

import re

# 示例字符串
text = "The rain in Spain falls mainly in the plain."

# 使用 re.findall 查找所有以 'ai' 结尾的单词
matches = re.findall(r"\b\w*ai\w*\b", text)

print(matches)
# 输出: ['rain', 'mainly', 'plain']

解释说明:

  • re.findall(pattern, string):该函数返回一个列表,包含所有与模式匹配的非重叠匹配项。
  • \b:表示单词边界,确保我们匹配的是完整的单词而不是单词的一部分。
  • \w*:表示任意数量的字母、数字或下划线(即单词字符)。
  • ai:表示我们要查找的特定字符序列。
  • 该示例代码会查找并返回所有以 'ai' 结尾的单词。

上一篇:python遍历数组

下一篇:python repr

大家都在看

python时间格式

python ord和chr

python中的yield

python list.pop

python的for i in range

npm config set python

python代码简单

python读取文件夹

python中turtle

python 输出时间

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站