Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- def regex_replace(string, replace):
- regex = re.compile(r'(?P<start><!-- start Menu -->)(?P<middle>[\w\d\s]+)(?P<end><!-- end Menu -->)')
- output = r'\1' + replace + r'\3'
- return regex.sub(output, string)
- regex_replace('<!-- start Menu --> und <!-- end Menu -->', 'Hello World')
- # '<!-- start Menu -->Hello World<!-- end Menu -->'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement