import re


def replace(content, substitutions):
	"""Apply list of regex pairs (substitutions) with optional flags to content"""
	for sub in substitutions:
		content = re.sub(sub[0], sub[1], content, flags = (sub[2] if len(sub) > 2 else 0))
	return content