python 正则表达式截取一段字符串
博彩导航网站排行榜
博彩导航网站排行榜
当前位置 : 博彩导航网站排行榜 > 博彩导航网站排行榜

python 正则表达式截取一段字符串

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

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

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"]

不一定非要用正则。

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

printre.splitr?<=\.\s*?=%s % |.joinnames, string

广告位

博彩导航网站排行榜