L
Lionel Thiry
I'd like to make some kind of substitution like in a shell: "${var}".
For that purpose, I use this pattern: /\$\{(.*?)\}/.
But I also want to be able to escape those special caracters $, { and }.
Examples:
"${var\\}weird}" # which is a variable with "var{weird" as name
"\\${var}" # which is the simple string "${var}" with no substitution
Then I wrote that pattern:
/(?!\\)\$\{(.*?)(?!\\)\}/
But, well, it doesn't work at all.
After some tests:
puts "ok" if "\\{".match(/\\\{/) # display "ok"
puts "not ok" if "\\{".match(/(?!\\)\{/) # display "not ok"
It seems that (?!\\) doesn't fullfill its role of "match if re in (?!re)
doesn't match". What's wrong with my code? Please help!
My ruby version is the "One-Click Installer - Windows" v1.8.1-13.
Lio
For that purpose, I use this pattern: /\$\{(.*?)\}/.
But I also want to be able to escape those special caracters $, { and }.
Examples:
"${var\\}weird}" # which is a variable with "var{weird" as name
"\\${var}" # which is the simple string "${var}" with no substitution
Then I wrote that pattern:
/(?!\\)\$\{(.*?)(?!\\)\}/
But, well, it doesn't work at all.
After some tests:
puts "ok" if "\\{".match(/\\\{/) # display "ok"
puts "not ok" if "\\{".match(/(?!\\)\{/) # display "not ok"
It seems that (?!\\) doesn't fullfill its role of "match if re in (?!re)
doesn't match". What's wrong with my code? Please help!
My ruby version is the "One-Click Installer - Windows" v1.8.1-13.
Lio