Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # re_skip_quoted_etc.py
- import re
- input_line = '''HEY 'Python World!' THIS IS A TEST LINE "WITH SOME QUOTES".\nHERE IS A LINE WITH ""\"TRIPLE QUOTES"\"" included!\nI'M ALSO GLAD IT'S GREAT AT IGNORING APOSTROPHES.'''
- regexed = re.findall(r'("[^"]+"|\'[^\']+\'|"""[^"]+"""|\S+|\’[^\’]+\’|\n\s*|\s+)', input_line)
- print(regexed)
- print('')
- output = []
- s = ''
- for r in regexed:
- if r.startswith(('"', "'")):
- output += [s, r]
- s = ''
- elif '\n' in r:
- output += ['\n']
- else:
- for i, c in enumerate(r):
- s += c.lower() if i % 2 == 0 else c.upper()
- s += ''
- output += [s]
- output = ''.join(output)
- print(output)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement