import re
regex = re.compile(r"\bhighp(?:\s+\w+)*\s+(?:float|[ib]?vec[2-4]|mat[2-4](?:x[2-4])?)(*SKIP)(?!)|\b(?:const\s+)?float\b", flags=re.MULTILINE)
test_str = ("const float x;\n"
"float foo1;\n"
"highp const float foo1;\n"
"const highp float foo1;\n"
"precision highp float foo2;")
subst = "lowp $0"
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