How to represent a literal $ in regular expression replacement?

Hi,

I'm running into a problem doing a regexp search/replace where I'm using a group expression in the search and substituting it into the replacement using the $n syntax. Problem is that my replace text also includes a literal $ sign which I can't seem to get to work - keep getting a "you have entered a malformed replacement string" message when it tries to perform a replacement.

I've tried doubling up ($$) and escaping (\$), but neither works - what should I be doing?

Quick example:

Search for: (test)
Replace: $test.$1

or

Replace: \$test.$1

or

Replace: $$test.$1

2 comments
Comment actions Permalink

You need to escape the escape character too.
Search for: (test)
Replace:
$test.$1

Bas

Andrew Walters wrote:

Hi,

I'm running into a problem doing a regexp search/replace where I'm using a group expression in the search and substituting it into the replacement using the $n syntax. Problem is that my replace text also includes a literal $ sign which I can't seem to get to work - keep getting a "you have entered a malformed replacement string" message when it tries to perform a replacement.

I've tried doubling up ($$) and escaping (\$), but neither works - what should I be doing?

Quick example:

Search for: (test)
Replace: $test.$1

or

Replace: \$test.$1

or

Replace: $$test.$1

0

Please sign in to leave a comment.