Python Forum
Split string with multiple delimiters and keep the string in "groups"
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Split string with multiple delimiters and keep the string in "groups"
#1
Putting a title on this was hard so hopefully I can do a better job of explaining it here.

Let's say I had a string like this: .nnddd9999999999ddnn. (A) or like this: ''0000aaa0000'' (B)

I would like to be able to split those strings with multiple delimiters, but keep the strings "intact" like this: string A would become:
['.', 'nn', 'ddd', '9999999999', 'ddd', 'nn', '.']
string B would become:
['\'\'', '0000', 'aaa', '0000', '\'\'']

As you can see, each string is split with multiple delimiters, but the "chains of characters" are intact rather than it appearing like:
['.', 'n', 'n', 'd', 'd', 'd', '9', '9', '9'...]

The closest I have gotten is using re.split with a delimiter like (.|n|d|9) but that produces an array like:
['.', '', 'n', '', 'n', '', 'd', ''...]

How could I get this to work? Is using re.split even the best way?
Reply


Messages In This Thread
Split string with multiple delimiters and keep the string in "groups" - by DreamingInsanity - May-11-2020, 01:53 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I parse the string? anna17 4 323 Apr-10-2024, 10:26 AM
Last Post: DeaD_EyE
  remove gilberishs from a "string" kucingkembar 2 275 Mar-15-2024, 08:51 AM
Last Post: kucingkembar
  Matching string from a file tester_V 5 452 Mar-05-2024, 05:46 AM
Last Post: Danishhafeez
  Python3 string slicing Luchano55 4 624 Feb-17-2024, 09:40 AM
Last Post: Pedroski55
  Retrieve word from string knob 4 499 Jan-22-2024, 06:40 PM
Last Post: Pedroski55
  Writing a Linear Search algorithm - malformed string representation Drone4four 10 961 Jan-10-2024, 08:39 AM
Last Post: gulshan212
  Virtual Env changing mysql connection string in python Fredesetes 0 383 Dec-20-2023, 04:06 PM
Last Post: Fredesetes
  Comparing Dataframe to String? RockBlok 2 417 Nov-24-2023, 04:55 PM
Last Post: RockBlok
  Sample random, unique string pairs from a list without repetitions walterwhite 1 462 Nov-19-2023, 10:07 PM
Last Post: deanhystad
  extract substring from a string before a word !! evilcode1 3 549 Nov-08-2023, 12:18 AM
Last Post: evilcode1

Forum Jump:

User Panel Messages

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