![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | godot_n00b |
I am recoding a program from Python into GDScript and am getting stumped at the regular expressions portion. Here the troublesome code:
func replaceVars(vars,text):
for loop in range(len(re.findall(r'\{[^{}]*(?=\{)', text))+1):
for variable in vars:
if vars[var]:
text = re.sub ('\{'+var+r':([^|{}]+)\|([^|{}]+?)\}', r'\1', text)
else:
text = re.sub ('\{'+var+r':([^|{}]+)\|([^|{}]+?)\}', r'\2', text)
return text
I use this to remove options from a text and display names, pronouns, etc that align with choices that players have already made. For example, “hunger and cold had driven {female_character: Aurelia|Aurelius} from {female_character: her|his} little cubbyhole” would change to: “hunger and cold had driven Aurelius from his little cubbyhole” if the player had chosen a male character.