fork download
  1. import re
  2.  
  3. regex = r"(?s)/\*(?:(?!\*/|/\*).)*?\bCompiler_Warning\b(?:(?!\*/|/\*).)*\*/"
  4.  
  5. test_str = ("/*\n"
  6. "blablabla example \n"
  7. "blabla\n"
  8. "*/\n\n"
  9. "/* blabla\n"
  10. "Compiler_Warning blablalba\n"
  11. "*/\n\n"
  12. "/*\n"
  13. "blablabla example \n"
  14. "blabla\n"
  15. "*/\n\n"
  16. "/*\n"
  17. "blablabla example \n"
  18. "blabla\n"
  19. "*/\n\n"
  20. "/* blabla\n"
  21. "Compiler_Warning blablalba\n"
  22. "*/\n"
  23. "/* blabla\n"
  24. "Compiler_Warning blablalba\n"
  25. "*/\n"
  26. "/*\n"
  27. "blablabla example \n"
  28. "blabla\n"
  29. "*/\n"
  30. "/* blabla\n"
  31. "Compiler_Warning blablalba\n"
  32. "*/")
  33.  
  34. matches = re.finditer(regex, test_str, re.DOTALL)
  35.  
  36. for matchNum, match in enumerate(matches, start=1):
  37.  
  38. print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
  39.  
  40. for groupNum in range(0, len(match.groups())):
  41. groupNum = groupNum + 1
  42.  
  43. print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
  44.  
  45. # Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
Success #stdin #stdout 0.03s 9444KB
stdin
Standard input is empty
stdout
Match 1 was found at 33-72: /* blabla
Compiler_Warning blablalba
*/
Match 2 was found at 140-179: /* blabla
Compiler_Warning blablalba
*/
Match 3 was found at 180-219: /* blabla
Compiler_Warning blablalba
*/
Match 4 was found at 252-291: /* blabla
Compiler_Warning blablalba
*/