fork download
  1. #!/usr/bin/python
  2.  
  3. import re
  4.  
  5. star = r"[^\/]+"
  6. doubleStar = r".*"
  7. slash = r"\/"
  8. questionMark = r"\w"
  9. dot = r"\."
  10.  
  11. antPath = "a/b/c/**/pom.xml"
  12. expectedPath = r"foo\/[^\/]+\/bar\/.*\.ex\w"
  13.  
  14. # Apply transformation
  15. output = antPath.replace(r"/", slash).replace(r".", dot)
  16. output = re.sub(r"(?<!\*)\*(?!\*)", star, output)
  17. output = output.replace(r"**", doubleStar)
  18. output = output.replace(r"?", questionMark)
  19.  
  20. if ( output == expectedPath ):
  21. print "Success!"
  22. else:
  23. print "Failure..."
  24. print "filteredPath: ", output
  25. print "expectedPath: ", expectedPath
Success #stdin #stdout 0.02s 7132KB
stdin
Standard input is empty
stdout
Failure...
filteredPath:  a\/b\/c\/.*\/pom\.xml
expectedPath:  foo\/[^\/]+\/bar\/.*\.ex\w