fork download
  1. # coding=utf8
  2. # the above tag defines encoding for this document and is for Python 2.x compatibility
  3.  
  4. import re
  5.  
  6. regex = r"((?<= )[\w.]+$)(?=.*(?<= )(\1)$)"
  7.  
  8. test_str = ("src/test/resources\n"
  9. "|-- WPCDPS\n"
  10. "| `-- RiskIndicatorsEvaluationRuleTest.feature\n"
  11. "|-- Accelerated.feature\n"
  12. "|-- AcceptedAFS.feature\n"
  13. "|-- AgeValidationRemoval.feature\n"
  14. "|-- Anxiety.feature\n"
  15. "|-- CheckDisabledOccupation.feature\n"
  16. "|-- Extended.feature\n"
  17. "|-- Financal.feature\n"
  18. "|-- Fainancial.feature\n"
  19. "|-- FloridaSpecific.feature\n"
  20. "|-- Hypertension.feature\n"
  21. "|-- LifeForceOrPending.feature\n"
  22. "|-- LifestyleInformation.feature\n"
  23. "|-- MinValue.feature\n"
  24. "|-- Occupations\n"
  25. "| |-- OccupationTranslation.feature\n"
  26. "| |-- OccupationsWithPreConditions.feature\n"
  27. "| |-- Accelerated.feature\n"
  28. "| `-- OccupationsWithoutPreConditions.feature\n"
  29. "|-- Florida.feature")
  30.  
  31. matches = re.finditer(regex, test_str, re.MULTILINE | re.DOTALL)
  32.  
  33. for matchNum, match in enumerate(matches):
  34. matchNum = matchNum + 1
  35.  
  36. print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
  37.  
  38. for groupNum in range(0, len(match.groups())):
  39. groupNum = groupNum + 1
  40.  
  41. print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
  42.  
  43. # Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
  44.  
Success #stdin #stdout 0.02s 6916KB
stdin
Standard input is empty
stdout
Match 1 was found at 83-102: Accelerated.feature
Group 1 found at 83-102: Accelerated.feature
Group 2 found at 526-545: Accelerated.feature