re.split multiple delimiters problem - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: re.split multiple delimiters problem (/thread-19325.html) |
re.split multiple delimiters problem - gw1500se - Jun-23-2019 I'm trying to split a long string using both a colon and new line as delimiters. It is splitting on the colon but not the new line. I guess I need some help on the proper syntax for the new line character. TIA import re . . . entities=re.split('\n |: ',result) RE: re.split multiple delimiters problem - ichabod801 - Jun-23-2019 Do you want those spaces there? Note that the pipe (|) only works on characters or groups. Right now your re matches '\n ' or '\n: '. You want either '\n|:' (if you don't want to match the spaces) or '(\n )|(: )' (if you do want to match the spaces). RE: re.split multiple delimiters problem - gw1500se - Jun-24-2019 No, I don't. New eyes always help. Thanks, that fixed it. |