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

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

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

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教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

membalas semua (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'(?


    Muat turun terkini
    Lagi>
    kesan web
    Kod sumber laman web
    Bahan laman web
    Templat hujung hadapan
    Tentang kita Penafian Sitemap
    Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!