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
  Split single column to multiple columns SriRajesh 1 1,290 Jan-07-2022, 06:43 PM
Last Post: jefsummers
  Delimiters - How to skip some html tags from being translate Melcu54 0 1,619 May-26-2021, 06:21 AM
Last Post: Melcu54
  Parse String between 2 Delimiters and add as single list items lastyle 5 3,280 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 6,705 Feb-22-2021, 06:51 PM
Last Post: eddywinch82
  multiple condition if statement problem FelixReiter 3 2,540 Jan-11-2021, 08:07 AM
Last Post: FelixReiter
  Split string between two different delimiters, with exceptions DreamingInsanity 2 1,977 Aug-24-2020, 08:23 AM
Last Post: DreamingInsanity
  Python Hangman Game - Multiple Letters Problem t0rn 4 4,531 Jun-05-2020, 11:27 AM
Last Post: t0rn
  Split string with multiple delimiters and keep the string in "groups" DreamingInsanity 4 6,347 May-12-2020, 09:31 AM
Last Post: DeaD_EyE
  [split] Python Class Problem astral_travel 12 4,817 Apr-29-2020, 07:13 PM
Last Post: michael1789
  Problem with delimiters johnprada 5 2,639 Jan-29-2020, 10:17 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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