dc9f79b7
Posts: 9 Joined: 22.11.2021 13:14
Post
by dc9f79b7 » 22.11.2021 17:16
Input text: 0 1 2 3 4 5 6 7 8 9
Open Replace dialog (Ctrl+R) and enable regex mode (Alt+R)
Search string: \d
Replace string: \d
Press "Replace all" (Alt+A)
Result text: d d d d d d d d d d
If repeat with:
Search string: \d
Replace string: \\d
then result text (that expected result): \d \d \d \d \d \d \d \d \d \d
How to fix this behavior?
• CudaText 1.149.3 x64
• Windows 7 SP1 x64
main Alexey
Posts: 2708 Joined: 25.08.2021 18:15
Post
by main Alexey » 22.11.2021 18:37
The '\d' in the REPLACE field has no meaning! so editor reads it as "escaped d char" == "d".
The "\\d" is similar : "escaped slash + d".
What do you want to replace with what?
Maybe try to replace '\d' with '\\$0'.
dc9f79b7
Posts: 9 Joined: 22.11.2021 13:14
Post
by dc9f79b7 » 22.11.2021 19:10
It is necessary to replace any digits in the text with "\d":
"0" to "\d"
...
"9" to "\d"
Why use escaping for "\d" or "\u" or "\w" (but not for "[" or "]" or "^" etc) in the replacement string? Is the "Replace" field also in regex mode?
main Alexey
Posts: 2708 Joined: 25.08.2021 18:15
Post
by main Alexey » 22.11.2021 19:11
Somehow yes, it is-- some behaviour of the TRegExpr engine, which I may fix if its needed. How other good editors handle this case?
main Alexey
Posts: 2708 Joined: 25.08.2021 18:15
Post
by main Alexey » 22.11.2021 19:18
SublimeText: acts like Cud now!
VSCode: not like Cud.
Not sure we need to change this.
main Alexey
Posts: 2708 Joined: 25.08.2021 18:15
Post
by main Alexey » 22.11.2021 19:22
Supporting \ as escape is good - because we can set 'replace with' as '\n' and it will replace with EOLs. Same for '\t'.
dc9f79b7
Posts: 9 Joined: 22.11.2021 13:14
Post
by dc9f79b7 » 22.11.2021 19:27
Ok. What about large fragments of code or markup? Each time you will have to first escape all the characters in the replacement string text.
main Alexey
Posts: 2708 Joined: 25.08.2021 18:15
Post
by main Alexey » 22.11.2021 19:42
SublimeText users live with it somehow. maybe for large fragments, we should not use Regex.
dc9f79b7
Posts: 9 Joined: 22.11.2021 13:14
Post
by dc9f79b7 » 22.11.2021 19:47
Yes "\n", "\t", "\r" etc. - is good. But mode work with "\q" and other characters.
Maybe take into account only:
or make as option?
main Alexey
Posts: 2708 Joined: 25.08.2021 18:15
Post
by main Alexey » 22.11.2021 20:10
Now it's logical- each \ means escaping, so literal \ must be written as \\.
If I do \ not working in \d and \q, it will be less logical. hard for user to know when he needs escaping.