Reputation: 43
I have been working in an AutoIt program which is supposed to receive variables declared into a .ini file. Later those variables can can called using double curly brackets "{{}}" and single curly brackets "{}". Here is an example.
Variable is defined by user as: VAR1 = "C:\MyDir\"
When user calls {{VAR1}} it receives "C:\\MyDir\\"
When user calls {VAR1} it receives "C:\MyDir\"
Double curly brackets replaces "\" for "\\"; single curly brackets gives only the actual variable value.
The problems are:
1) User may use curly brackets in variable definition: {VAR1} = "C:\MyDir\" Or {{VAR1}} = "C:\MyDir\" ...
2) User may write a text using curly brackets and call a variable inside the text:
My sample text {{{VAR1}}} my sample text.
User calls {VAR1} variable using the second {{VAR1}} curly bracket and want the result to be displayed inside the third curly bracket.
User expects this: "My sample text {C:\MyDir} my sample text."
To avoid the potential problems of this curly brackets recurssion I would like to define a rule to use escaped curly brackets "{" when user wants to write a real curly bracket and a non-escaped curly bracket when user is calling a variable.
Based on the previous explanation, I need a regular expression capable of resolving the following example:
\{{{\{VAR1\}}}\}
The escaped curly brackets must be ignored and function should return \{VAR1\} as the variable name. In this case variable "real" name is "{VAR1}".
I hope you can help me.
Best regards,
Aeolis
Upvotes: 1
Views: 315
Reputation: 43
Thank you stribizhev for your correction and for the link to "regex101.com" (very good source for help). Yes, one solution to my problem is the pattern: (?<!\\)\{(?<!\\)\{(.*)(?<!\\)\}(?<!\\)\}
Thank you all!
Best regards,
Aeolis
Upvotes: 1