Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij Idea: how to put dollar sign to the replaced content

When You have a replace and you want to replace text with something that contains $ You get a malformed replacement string (interpreter thinks its a variable reference). The $$ doesn't work.

like image 630
kubek2k Avatar asked Nov 02 '12 20:11

kubek2k


People also ask

How do I replace a word in a regular expression?

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. The string 3foobar4 matches the regex /\d. *\d/ , so it is replaced.


2 Answers

As featured in Regular Expression Syntax Reference - you can use \\$ to escape $ sign.

like image 58
Vic Avatar answered Oct 05 '22 03:10

Vic


\ $1 if IDE from JetBrains you need type space character between slash and sign dollar

like image 31
extraterrestrial martian Avatar answered Oct 05 '22 02:10

extraterrestrial martian