Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >>> import re
- >>> mystring = r"This is n a test r"
- >>> p = re.compile( "\\(\S)" )
- >>> p.sub( "\1", mystring )
- 'This is n a test r'
- >>> p.sub( "\\\1", mystring )
- 'This is \n a test \r'
- >>> p.sub( "\\1", mystring )
- 'This is \1 a test \1'
- >>> mystring = r"This is n a test r"
- >>> mystring.decode('string-escape')
- 'This is n a test r'
- >>> print mystring.decode('string-escape')
- This is
- a test
- >>>
- "\n" == r"n"
- >>> import re
- >>> mystring = r"This is \n a test \r"
- >>> p = re.compile( r"[\][\](.)" )
- >>> print p.sub( r"\1", mystring )
- This is n a test r
- >>>
- >>> d = {'n':'n', 'r':'r', 'f':'f'}
- >>> p = re.compile(r"[\]([nrfv])")
- >>> print p.sub(lambda mo: d[mo.group(1)], mystring)
- This is
- a test
- >>>
- This is \n a test \r
- This is \n a test \r
- This is n a test r
- 'This is \n a test \r'
- This is n a test r
- >>> mystring = r"This is n a test r"
- >>> mystring
- 'This is \n a test \r'
- >>> print mystring
- This is n a test r
- >>> mystring = r"This is n ridiculous"
- >>> print mystring
- This is n ridiculous
- >>> p = re.compile( r"\(S)" )
- >>> print p.sub( 'bloody', mystring )
- This is bloody ridiculous
- >>> print p.sub( r'1', mystring )
- This is n ridiculous
- >>> print p.sub( r'\1', mystring )
- This is 1 ridiculous
- >>> print p.sub( r'\1', mystring )
- This is n ridiculous
- This is
- ridiculous
Add Comment
Please, Sign In to add comment