我有以下字符串
random_string = '12:58 PM word \n12:20PM person \n12:39PM'
I am doing the following:
re.split(r'[\n]+\d',random_string)
And I get:
['12:58 PM word ', '2:20PM person ', '2:39PM']
But I want:
['12:58 PM word ', '12:20PM person ', '12:39PM']
你知道怎么做吗?你知道吗
Tags:
从https://docs.python.org/2/library/re.html:
所以,在你的情况下:
在regex中使用lookahead避免在换行后匹配数字:
\n+(?=\d)
将在换行符上拆分,当一个数字正好位于换行符之后。你知道吗\n
放入character类。你知道吗相关问题 更多 >
编程相关推荐