Python Forum
splitting on 2 or more possible characters
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
splitting on 2 or more possible characters
#7
I personally find re.compile quite helpful when dealing with regular expressions. It makes split expression more concise:

>>> import re
>>> a = 'bacon-eggs_spam*ham!foo&bar'
>>> breakpoints = re.compile('[-_*!&]')
>>> breakpoints.split(a)
['bacon', 'eggs', 'spam', 'ham', 'foo', 'bar']
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
RE: splitting on 2 or more possible characters - by perfringo - Sep-03-2018, 04:10 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Remove escape characters / Unicode characters from string DreamingInsanity 5 14,455 May-15-2020, 01:37 PM
Last Post: snippsat
  splitting or parsing control characters Skaperen 19 11,590 May-26-2017, 07:27 PM
Last Post: zivoni
  splitting a string by 2 characters Skaperen 8 9,182 Dec-27-2016, 06:14 AM
Last Post: wavic

Forum Jump:

User Panel Messages

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