import re
regex = re.compile(r"^(\s*(?<!#)\s*PRIMER_PRODUCT_SIZE_RANGE\s*)=.*$", flags=re.MULTILINE)
test_str = ("# PRIMER_PRODUCT_SIZE_RANGE=xxx-yyy\n"
"PRIMER_PRODUCT_SIZE_RANGE=100-300\n"
"PRIMER_NUM_RETURN=3\n"
"PRIMER_MAX_END_STABILITY=9.0\n\n"
"PRIMER_MAX_HAIRPIN_TH=24.0")
subst = "\\1=500-300"
result = regex.sub(subst, test_str)
if result:
print(result)
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html