# 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
In reply to Re^6: How to replace envs in path?
by hv
in thread How to replace envs in path?
by ovedpo15
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |