0

I have a string which I want to split which contains quotes, say

s = '1.2.3."4.5".0.6.7'

I now want to handle "4.5" as one element since it's quoted:

>>> s.split(".", handle_quotes=True)
['1', '2', '3', '"4.5"', '0', '6', '7']

Can I do this with Pythons on-board tools?

Background: my primary goal is to find the last element which is not a number, in order to split the list at this position:

def split_me(s):
    return magic

print(split_me('1.2.3."4.5".0.6.7'))

prints

('1.2.3."4.5"', '0.6.7')
frans
  • 8,868
  • 11
  • 58
  • 132
  • 2
    Does this answer your question? [How to split but ignore separators in quoted strings, in python?](https://stackoverflow.com/questions/2785755/how-to-split-but-ignore-separators-in-quoted-strings-in-python) (multiple solution: regex, csv, custom parser, etc.) also [Split string on commas but ignore commas within double-quotes?](https://stackoverflow.com/questions/8069975/split-string-on-commas-but-ignore-commas-within-double-quotes) (direct csv solution) – aloisdg Feb 03 '20 at 13:42
  • or just split by quotes first, and then if string starts or ends with dot then split by dot. and merge resulting arrays – Yehor Androsov Feb 03 '20 at 13:43

0 Answers0