Search & Replace -- Regepx $ not working as expected

Answered

 

I try to use the IntelliJ editor to do some complex Search&Replace operation. One of them is needed to change every end of the text inside the editor.

Trying to use $ inside a regex doesn't work as expected, no match is found :-(

A corresponding action to change something at the beginning of a line works as expected.

It's the same behavior for Windows and Mac OS with the current IntelliJ version.

 

Has anyone an explanation why IntelliJ works different the all the other editors I'm using?

 

Thanks

Peter

 

0
12 comments

Please clarify what you want to do, you original regex is not visible on the screenshot.

0

Sorry Serge ...
In the example I tried to replace "End Of Line" by a different Character. The S&R pattern are e.g.

 

The same for replacing the Begin-Of-Line with ^ instead of $ works as expected.

0

Can't reproduce in 2022.2.4 or 2022.3 release. Please update.

0

Try with the default settings: File | Manage IDE Settings | Restore Default Settings...: https://i.imgur.com/kbrkC7w.png.

Try File | Invalidate Caches | Invalidate and Restart.

0

I can replicate the issue in a fresh install of IDEA Community Edition. It doesn't happen for my install of Ultimate, so I dunno what's going on. I uploaded a screen recording to demonstrate: https://youtu.be/pNNSqmflw1w

The workaround is to use groups:

(.)$ 

Substitution is then:

$1<other text>
0

Hi Serge,

 

sorry for the late response. But your "magic" doesn't work, a simple Search&replace of the EOL is still not working. 

But I've found out, that "Any Character"+EOL works. In the above example the regex 6$ matches 4 line (which is correct).

Best regards

Peter

0

IntelliJ IDEA 2022.3 (Ultimate Edition)
Build #IU-223.7571.182, built on November 29, 2022
Licensed to Peter Stöhr
Subscription is active until January 19, 2023.
For educational use only.
Runtime version: 17.0.5+1-b653.14 aarch64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 13.0.1
GC: G1 Young Generation, G1 Old Generation
Memory: 2048M
Cores: 10
Metal Rendering is ON

Kotlin: 223-1.7.20-release-201-IJ7571.182

0

WORKAROUND: ensure there is EOL at the end of the file. This can be done by enabling Settings (Preferences on macOS) | Editor | General | Ensure every saved file ends with a line break.

1

Cool, that really helps!

Thanks!

1

Please sign in to leave a comment.