Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # re_quotify.py
- import re
- def re_quotify(text):
- pattern = r'"""[^"]*"""|"[^"]*"|\'[^\']*\'|\S+|\s+|\\[ntrbf\\"\']'
- matches = re.findall(pattern, text)
- final = []
- sss = ''
- while matches:
- s = matches.pop(0)
- if s.startswith(('"', "'")):
- if s == '""':
- s += matches.pop(0)
- final += [sss, s]
- sss = ''
- else:
- sss += s
- return final + [sss]
- text = 'This is "a sample" text\nwith\tmultiple\rstrings and """special characters: \', \", \\, \b, \f.)"""\n"""This is a\nmultiline\nstring."""\nThis is \'a single-quoted\' string.'
- text += '''\nI'M ALSO GLAD IT'S GREAT AT IGNORING APOSTROPHES.'''
- strings = re_quotify(text)
- print(strings)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement