Python Forum
re.split multiple delimiters problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
re.split multiple delimiters problem
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).
Craig "Ichabod" O'Brien -
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
No, I don't. New eyes always help. Thanks, that fixed it.

Possibly Related Threads…
Thread Author Replies Views Last Post
  Delimiters - How to skip some html tags from being translate Melcu54 0 294 May-26-2021, 06:21 AM
Last Post: Melcu54
  Parse String between 2 Delimiters and add as single list items lastyle 5 610 Apr-11-2021, 11:03 PM
Last Post: lastyle
  Pandas: how to split one row of data to multiple rows and columns in Python GerardMoussendo 4 1,171 Feb-22-2021, 06:51 PM
Last Post: eddywinch82
  multiple condition if statement problem FelixReiter 3 573 Jan-11-2021, 08:07 AM
Last Post: FelixReiter
  Split string between two different delimiters, with exceptions DreamingInsanity 2 656 Aug-24-2020, 08:23 AM
Last Post: DreamingInsanity
  Python Hangman Game - Multiple Letters Problem t0rn 4 1,275 Jun-05-2020, 11:27 AM
Last Post: t0rn
  Split string with multiple delimiters and keep the string in "groups" DreamingInsanity 4 1,669 May-12-2020, 09:31 AM
Last Post: DeaD_EyE
  [split] Python Class Problem astral_travel 12 1,623 Apr-29-2020, 07:13 PM
Last Post: michael1789
  Problem with delimiters johnprada 5 1,027 Jan-29-2020, 10:17 AM
Last Post: DeaD_EyE
  Problem with delimiters johnprada 1 633 Jan-28-2020, 04:27 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020