in reply to Re^5: How to replace envs in path?
in thread How to replace envs in path?
# look # behind |------ $1 ------| my $with_braces = qr/ (?<!\\) ( \$ \{ (\w+) \} ) /x; my $without_braces = qr/ (?<!\\) ( \$ (\w+) ) /x; # |$2 |
Note that this use of lookbehind is generally not a safe way to look for an unescaped $, because generally when backslashes are used for escaping, they are also used for escaping backslashes themselves: \\$HOME would then be considered an escaped backslash followed by a replaceable variable reference.
In this context, it's less obvious what is correct since backslashes are not generally being used for escaping. As such, I'm not sure that the spec is coherent as a whole - it looks like there would be no way to express a string that should have one or more actual backslashes followed by a variable.
Hugo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: How to replace envs in path?
by BillKSmith (Monsignor) on May 24, 2022 at 13:15 UTC |