How to divide a string by line break or period with Python regular expressions?

PythonServer Side ProgrammingProgramming

The following code splits given string by a period and a line break as follows

Example

import re
s = """Hi. It's nice meeting you.
My name is Jason."""
result = re.findall(r'[^\s\.][^\.\n]+', s)
print result

Output

This gives the following output

['Hi', "It's nice meeting you", 'My name is Jason']
raja
Published on 28-Dec-2017 17:45:19
Advertisements