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"(.*)(point\s+c\w+)(.*)point\s+c\w+(.*)|(.+)\bpoint\s+c\w+(.*)"
  7.  
  8. test_str = ("Street_Name\n"
  9. "Point Chevalier Road Point Cheva\n"
  10. "Point chevalier Road Point Chev\n"
  11. "Point Chevalier Road Point Cheval\n"
  12. "Point Chevalier Road Point Chevali\n"
  13. "Kings Road Point Chevalier\n"
  14. "Point Chevalier")
  15.  
  16. subst = "\\1\\2\\3\\4\\5\\6"
  17.  
  18. # You can manually specify the number of replacements by changing the 4th argument
  19. result = re.sub(regex, subst, test_str, 0, re.IGNORECASE | re.MULTILINE)
  20.  
  21. if result:
  22. print (result)
  23.  
  24. # Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
  25.  
Success #stdin #stdout 0.02s 28384KB
stdin
Standard input is empty
stdout
Street_Name
Point Chevalier Road 
Point chevalier Road 
Point Chevalier Road 
Point Chevalier Road 
Kings Road 
Point Chevalier