我可以用Python中的regex搜索特定的行吗?

2024-04-26 02:33:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我想使用re.search()在我选择的行上搜索一个模式,或者从我指定的行开始搜索。这可能吗?你知道吗


Tags: research模式行上
1条回答
网友
1楼 · 发布于 2024-04-26 02:33:51

当然:使用普通的字符串操作隔离该行,并只将该行传递给re.search()。你知道吗

例如:

lines = data.split('\n')
a = re.search('regex', lines[3])

相关问题 更多 >