开发者

To split on the basis of space and special character in python

开发者 https://www.devze.com 2023-02-19 23:07 出处:网络
v=开发者_运维百科vi nod-u i want to split this string to obtain l=[vi],[nod],[u] l.split(\" \") splits on the basis of space.

v=开发者_运维百科vi nod-u

i want to split this string to obtain

l=[vi],[nod],[u]

l.split(" ") splits on the basis of space.

And i dont know the usage of the regular expression import functions properly. Could anyone explain how to do that?


Are you trying to split the string to get words? If so, try the following:

>>> import re
>>> pattern = re.compile(r'\W+')
>>> pattern.split('vi nod-u')
['vi', 'nod', 'u']
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号