Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- text = "hello23 the2e are 13 5.12apples *specially_x00123 named"
- text_cleaned = "hello## the#e are ## #.##apples *specially_x00123 named"
- p1 = r'd(?<!*w+_w+)'
- p2 = r'(?:*[a-z]+_w+)b|d'
- # coding=utf8
- # the above tag defines encoding for this document and is for Python 2.x compatibility
- import re
- regex = r"(d)"
- test_str = "hello23 the2e are 13 5.12apples *specially_x00123 named"
- subst = "#"
- # You can manually specify the number of replacements by changing the 4th argument
- result = re.sub(regex, subst, test_str, 0, re.MULTILINE)
- if result:
- print (result)
- # 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