micro icon indicating copy to clipboard operation
micro copied to clipboard

Cant replace "$" character in file

Open v3ai opened this issue 1 year ago • 11 comments

Description of the problem or steps to reproduce

Have a file (Personally an .html in my case) and try to use replaceall "$" "other string"

Specifications

Version: 2.0.11 Commit hash: 225927b9

Commit hash: OS: Linux mint Terminal: Bash

v3ai avatar May 31 '23 05:05 v3ai

$ is the special regex symbol. Escape it:

replaceall \$

237dmitry avatar May 31 '23 06:05 237dmitry

$ is the special regex symbol. Escape it:

replaceall \$

Still running into problems for some reason

example

amount of money = $4000

replaceall $ text and also replaceall "$" text

v3ai avatar May 31 '23 06:05 v3ai

amount of money = $4000

To replace the only $

replaceall \$

Variants to replace $4000

replaceall \$\S+
replaceall \$\d+
replaceall \$4000

replace $ with text

replaceall \$ 'dollars '

237dmitry avatar May 31 '23 06:05 237dmitry

Hey I'm going to try to upgrade to the newest version of micro, but It still doesn't work

v3ai avatar May 31 '23 15:05 v3ai

still getting problems

v3ai avatar May 31 '23 15:05 v3ai

still getting problems

I do not know. In my case all works. Are you sure that $ sign is \U0024?

micro-1 micro-2

237dmitry avatar May 31 '23 15:05 237dmitry

That worked, thank you so much! needed the ' ' characters

v3ai avatar Jun 02 '23 04:06 v3ai

needed the ' ' characters

I do not know what is difference but on Windows it works without ''.

237dmitry avatar Jun 02 '23 13:06 237dmitry

I'm running into a similar issue, but with the replacement value. None of these seem to work, they just end up replacing the search value with an empty string

replace foo $HOME replace foo $HOME replace foo '$HOME' replace foo "$HOME"

encodis avatar Jan 25 '24 10:01 encodis

@encodis the replace command ends up calling Regexp.Expand (which uses $ for capture groups in the replacement). The proper way to escape the $ is replace foo $$HOME.

Andriamanitra avatar Jan 25 '24 11:01 Andriamanitra

@Andriamanitra Ah! thank you!

encodis avatar Jan 25 '24 12:01 encodis