Python Forum

Full Version: re.split multiple delimiters problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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)
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).
No, I don't. New eyes always help. Thanks, that fixed it.