Elizabeth
0
Q:

re.sub in python example

import re
>>> m = re.search('(?<=abc)def', 'abcdef')
>>> m.group(0)
'def'
3
import re

result = re.sub(pattern, repl, string, count=0, flags=0);
2
>>> import re
>>> m = re.search('(?<=abc)def', 'abcdef')
>>> m.group(0)
'def'
1
result = re.sub('abc',  '',    input)           # Delete pattern abc
result = re.sub('abc',  'def', input)           # Replace pattern abc -> def
result = re.sub(r'\s+', ' ',   input)           # Eliminate duplicate whitespaces using wildcards
result = re.sub('abc(def)ghi', r'\1', input)    # Replace a string with a part of itself
0

New to Communities?

Join the community