Python Forum
splitting or parsing control characters
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
splitting or parsing control characters
#13
(May-26-2017, 03:07 PM)zivoni Wrote: is only slightly worse than
re.split('([{}]*)'.format(cs), 'Split   this string and   store    splits')
posted before that gives list instead of list of tuples.

Sorry, professor, but split does not give you "run" of the same separators - I believe OP asked to preserve each separator with its length

(May-26-2017, 03:07 PM)zivoni Wrote: Neither one of them does what is wanted (split different separators while keeping "runs" of same separators) without some additional processsing.
list(itertools.chain(*re.findall(r'([^{0}]+)({0}*)'.format(cs), 'Split   this   string and   store splits')))
Mission accomplished. Yalla, next question?

Oh, and space was used just as an example
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply


Messages In This Thread
RE: splitting or parsing control characters - by volcano63 - May-26-2017, 03:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Remove escape characters / Unicode characters from string DreamingInsanity 5 21,340 May-15-2020, 01:37 PM
Last Post: snippsat
  splitting on 2 or more possible characters Skaperen 6 4,810 Sep-03-2018, 04:10 AM
Last Post: perfringo
  splitting a string by 2 characters Skaperen 8 10,736 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