This article mainly introduces Python's method of segmenting strings according to multiple characters, which involves the technique of the right expression matching in Python, which is very practical, and needs friends to refer to
This example describes how Python splits strings by multiple characters. Share to everyone for your reference. The specific analysis is as follows:
This Python code splits the string through the regular expression, using w as the delimiter, as long as it is not alphanumeric and it is separated.
?
| 1 2 3 |
import Re DATA = "Hey, you-what are you doing here! Welcome to JB51? "Print Re.findall (r" [w ']+ ", DATA) |
The output is as follows
Copy code code as follows: [' Hey ', ' You ', ' What ', ' are ', ' you ', ' doing ', ' here ', ' welcome ', ' to ', ' jb51 '
]
I hope this article will help you with your Python programming.