Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. text = "hello23 the2e are 13 5.12apples *specially_x00123 named"
  2.  
  3. text_cleaned = "hello## the#e are ## #.##apples *specially_x00123 named"
  4.  
  5. p1 = r'd(?<!*w+_w+)'
  6.  
  7. p2 = r'(?:*[a-z]+_w+)b|d'
  8.  
  9. # coding=utf8
  10. # the above tag defines encoding for this document and is for Python 2.x compatibility
  11.  
  12. import re
  13.  
  14. regex = r"(d)"
  15.  
  16. test_str = "hello23 the2e are 13 5.12apples *specially_x00123 named"
  17.  
  18. subst = "#"
  19.  
  20. # You can manually specify the number of replacements by changing the 4th argument
  21. result = re.sub(regex, subst, test_str, 0, re.MULTILINE)
  22.  
  23. if result:
  24. print (result)
  25.  
  26. # Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement