fork download
  1. import re
  2.  
  3. regex = r'''
  4. ("{3}|["\'])(?:(?=(\\?))\2.)*?\1
  5. '''
  6.  
  7. test_str = ('''
  8. """
  9. Multi-line text 2 "'
  10. """
  11.  
  12. "String"
  13.  
  14. "12345"
  15.  
  16. 'abcde'
  17.  
  18. 'It\\'s'
  19.  
  20. """Multi-line text"""
  21. ''')
  22.  
  23. matches = re.finditer(regex, test_str, re.VERBOSE | re.DOTALL)
  24.  
  25. for matchNum, match in enumerate(matches):
  26. matchNum = matchNum + 1
  27.  
  28. print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
Success #stdin #stdout 0.02s 27712KB
stdin
Standard input is empty
stdout
Match 1 was found at 1-29: """
Multi-line text 2 "'
"""
Match 2 was found at 31-39: "String"
Match 3 was found at 41-48: "12345"
Match 4 was found at 50-57: 'abcde'
Match 5 was found at 59-66: 'It\'s'
Match 6 was found at 68-89: """Multi-line text"""