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


Possibly Related Threads…
Thread Author Replies Views Last Post
  Parse String between 2 Delimiters and add as single list items lastyle 5 260 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 602 Feb-22-2021, 06:51 PM
Last Post: eddywinch82
  multiple condition if statement problem FelixReiter 3 338 Jan-11-2021, 08:07 AM
Last Post: FelixReiter
  Split string between two different delimiters, with exceptions DreamingInsanity 2 516 Aug-24-2020, 08:23 AM
Last Post: DreamingInsanity
  Python Hangman Game - Multiple Letters Problem t0rn 4 1,059 Jun-05-2020, 11:27 AM
Last Post: t0rn
  Split string with multiple delimiters and keep the string in "groups" DreamingInsanity 4 1,258 May-12-2020, 09:31 AM
Last Post: DeaD_EyE
  [split] Python Class Problem astral_travel 12 1,299 Apr-29-2020, 07:13 PM
Last Post: michael1789
  Problem with delimiters johnprada 5 878 Jan-29-2020, 10:17 AM
Last Post: DeaD_EyE
  Problem with delimiters johnprada 1 513 Jan-28-2020, 04:27 PM
Last Post: buran
  Problem with accepting multiple string inputs Ryan_Todd 5 870 Jan-22-2020, 06:12 PM
Last Post: buran

Forum Jump:

User Panel Messages

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