Python Forum
splitting a string by 2 characters
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
splitting a string by 2 characters
#1
i want to split a string at each place where 2 different characters might appear.

'some text<some tag>more text'.split2('<','>')

--> ['some text','some tag','more text']

yes, this example is splitting HTML, so that may be a bad example.  consider this outside of the scope of HTML so your thinking does not converge on HTMLParser.  Maybe it would be nice if str.split could be upgraded to do this like:

'some text<some tag>more text'.split(['<','>'])
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
splitting a string by 2 characters - by Skaperen - Dec-26-2016, 05:25 AM
RE: splitting a string by 2 characters - by wavic - Dec-26-2016, 07:01 AM
RE: splitting a string by 2 characters - by wavic - Dec-26-2016, 07:18 AM
RE: splitting a string by 2 characters - by wavic - Dec-26-2016, 07:55 AM
RE: splitting a string by 2 characters - by wavic - Dec-27-2016, 06:14 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  doing string split with 2 or more split characters Skaperen 22 2,949 Aug-13-2023, 01:57 AM
Last Post: Skaperen
  splitting file into multiple files by searching for string AlphaInc 2 1,081 Jul-01-2023, 10:35 PM
Last Post: Pedroski55
  How do I check if the first X characters of a string are numbers? FirstBornAlbratross 6 1,716 Apr-12-2023, 10:39 AM
Last Post: jefsummers
Question [SOLVED] Delete specific characters from string lines EnfantNicolas 4 2,364 Oct-21-2021, 11:28 AM
Last Post: EnfantNicolas
  Extract continuous numeric characters from a string in Python Robotguy 2 2,758 Jan-16-2021, 12:44 AM
Last Post: snippsat
  Python win32api keybd_event: How do I input a string of characters? JaneTan 3 3,997 Oct-19-2020, 04:16 AM
Last Post: deanhystad
  How to get first two characters in a string scratchmyhead 2 2,176 May-19-2020, 11:00 AM
Last Post: scratchmyhead
  Remove escape characters / Unicode characters from string DreamingInsanity 5 14,304 May-15-2020, 01:37 PM
Last Post: snippsat
  Splitting a string twice bazcurtis 2 5,724 Mar-09-2020, 02:54 PM
Last Post: perfringo
  Replacing characters in a string with a list cjms981 1 1,878 Dec-30-2019, 10:50 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

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