Recently, I have been creating an editor in Python 3.7.6 (using tkinter), I created the following syntax for highlighting single, double and triple quotes but I want to exclude all the characters inside a curly bracket of an f-string, I tried using [^\{(.*)\}]
as a negated set, but then realized it wouldn't work. I tried searching on the internet but all those didn't fit in with my regex.
This is the regex part of the code :
def regex_groups(self, name, alternates):
return "(?P<%s>" % name + "|".join(alternates) + ")"
stringprefix = r"(\bB|b|br|Br|bR|BR|rb|rB|Rb|RB|r|u|R|U|f|F|fr|Fr|fR|FR|rf|rF|Rf|RF)?"
sqstring = stringprefix + r"'[^'\\\n]*(\\.[^'\\\n]*)*'?"
dqstring = stringprefix + r'"[^"\\\n]*(\\.[^"\\\n]*)*"?'
sqqqstring = stringprefix + r"'''[^'\\]*((\\.|'(?!''))[^'\\]*)*(''')?"
dqqqstring = stringprefix + r'"""[^"\\]*((\\.|"(?!""))[^"\\]*)*(""")?'
string = self.regex_groups("STRING", [sqqqstring, dqqqstring, sqstring, dqstring])
What I tried was to break stringprefix
into two strings r"(f|F|fr|Fr|fR|FR|rf|rF|Rf|RF)?"
and r"(B|b|br|Br|bR|BR|rb|rB|Rb|RB|r|u|R|U)?"
and then using both with sqstring, dqstring, sq3string and dq3string
separately, but it wasn't successful.
Here is one of the part of the regex testing :
Please help me !
Any help is appreciated ! :)