jweinst1
1/22/2016 - 6:13 PM

uses regex to replace a string between two entity patterns

uses regex to replace a string between two entity patterns

#replaces a single entity between two patterns
def replacebetween(patt, string, repl):
    import re
    target = re.match(patt, string)
    g = list(target.groups())
    g[1] = repl
    return ''.join(g)