regex - How do You Split String into Words and Special Characters in Python? -


I want to split a string into [a-zA-Z] and some Special characters that contain @ and # symbol

messages = "I @split, in #words, and any other that does not matter Most special character (., & Gt;) "

Expected Result:

['I', ' I ',' to ',' b ',' @split ',', ',' in ',' #words', ',', 'and', 'some', 'other', 'chees' ',' ',' ',' ',' ',' ',' ',' ',' 'Special' ',' character ',' (','. ',', ',' ',' ',' '' ' / Code >

How can I get it into Python?

How about:

  re.findall (r " [A-za-z @ #] + | \ s ", message)  

Pattern term matches any sequence of characters (here, more than the letters @ < / Code> and # ), or any non-white space character.


Comments