7

Python爬虫编程思想(35):用正则表达式搜索、替换和分隔字符串

 3 years ago
source link: https://blog.csdn.net/nokiaguy/article/details/120541301
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Python爬虫编程思想(35):用正则表达式搜索、替换和分隔字符串

专栏收录该内容
36 篇文章 2 订阅 ¥29.90 ¥99.00

目录

1. 用sub和subn搜索与替换

2. 使用split分隔字符串


1. 用sub和subn搜索与替换

        sub函数与subn函数用于实现搜索和替换功能。这两个函数的功能几乎完全相同,都是将某个字符串中所有匹配正则表达式的部分替换成其他字符串。用来替换的部分可能是一个字符串,也可以是一个函数,该函数返回一个用来替换的字符串。sub函数返回替换后的结果,subn函数返回一个元组,元组的第1个元素是替换后的结果


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK