Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using '$' in the replacing text / escaping it (RegEx-mode)

Tags:

phpstorm

my question is not about RegEx in general but about PhpStorm's search-replace-functionality with RegEx switched on.

I use PhpStorm and I want to use the dollar-sign in the replacing text.

But when I do that using RegEx mode then $ becomes the special char for identifying back references.

So I have to escape it.

But neither \$ nor $$ is accepted by PhpStorm.

How do I escape $ in RegEx-mode?

like image 659
Raffael Avatar asked Oct 22 '11 11:10

Raffael


People also ask

How do you escape in regex?

The \ is known as the escape code, which restore the original literal meaning of the following character. Similarly, * , + , ? (occurrence indicators), ^ , $ (position anchors) have special meaning in regex. You need to use an escape code to match with these characters.

How do you escape the dollar sign in regex?

You can escape dollar signs with a backslash or with another dollar sign. So $, $$, and \$ all replace with a single dollar sign.

Can I use regex in replace?

How to use RegEx with . replace in JavaScript. To use RegEx, the first argument of replace will be replaced with regex syntax, for example /regex/ . This syntax serves as a pattern where any parts of the string that match it will be replaced with the new substring.


1 Answers

you have to use \\$ for the replacing text.

searching for $ is done with \$.

like image 88
Raffael Avatar answered Oct 17 '22 18:10

Raffael