如何通过 Python 正则表达式按行分隔符或句号分隔字符串?
以下代码通过句号和行分隔符以以下方式拆分给定的字符串
示例
import re s = """Hi. It's nice meeting you. My name is Jason.""" result = re.findall(r'[^\s\.][^\.\n]+', s) print result
输出
输出结果如下
['Hi', "It's nice meeting you", 'My name is Jason']
广告
以下代码通过句号和行分隔符以以下方式拆分给定的字符串
import re s = """Hi. It's nice meeting you. My name is Jason.""" result = re.findall(r'[^\s\.][^\.\n]+', s) print result
输出结果如下
['Hi', "It's nice meeting you", 'My name is Jason']