python 正则表达式截取一段字符串
高洛峰
高洛峰 2016-11-11 09:38:03
0
1
783

标题可能表达的不清楚,看下面的例子。

比如有一段字符串和一个名字列表:

string = "David comes from china. he loves watching tv shows. Tom is an american, he loves games. Rick blablabla" names = ["David", "Tom", "Rick"]

想写个函数,要return的结果:

r = ["David comes from china. he loves watching tv shows.", "Tom is an american, he loves games.", "Rick blablabla"]

不一定非要用正则。

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all (1)
三叔
string = "David comes from china. he loves watching tv shows. Tom is an american, he loves games. Rick blablabla" names = ["David", "Tom", "Rick"] import re print(re.split(r'(?


    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!