1、首先下载Anaconda
2、在Anaconda中安装Jupyter notebook
3、打开Jupyter notebook只需要在终端输入jupyter notebook
4、打开一个网页,点新建,选择相应版本的python,我选择了python 3
5、在打开的网页编辑器上输入如下代码:
import re
test_string = "我是一个中国人。在学习爬虫。爬虫非常有趣。"
regex = "爬虫"
p_string = test_string.split("。")
for line in p_string:
if re.search(regex,line) is not None:
print(line)
print(p_string)
输出结果:
在学习爬虫
爬虫非常有趣
['我是一个中国人', '在学习爬虫', '爬虫非常有趣', '']