Reputation: 1763
Visual studio code under certain circumstances doesn't seem to match letters and I'm not sure if I'm missing something incredibly obvious or if this is a bug. In my case I'm standardizing a code base and I want to change things like:
}
else {
Write-Warning
to:
} else {
Write-Warning
I wrote the following regex:
((?:(?=[^\r\n])\s))\}
.*else \{
(there's a newline here you can't see)
to identify the lines I want to change. On one file it worked just fine:
However on the next file I got the following:
As you can see I changed the regex a bit, but it works as expected and matches everything up to and include the 'e'. However, if I add an l:
It no longer matches. I tried copying and pasting the 'l' thinking maybe it was some weird unicode problem or something - still doesn't match. Am I missing something?
I checked the line endings with a hex editor and confirmed everything was only 0A
(LF). There were no carriage returns:
I also confirmed in Visual Studio code the line endings were set to LF.
Upvotes: 1
Views: 391
Reputation: 626861
If you use a regex for the task, consider changing yours to
([^\S\r\n])\}\n[^\S\r\n]*else[^\S\r\n]*\{
Replace with $1} else {
.
See the regex demo.
Details
([^\S\r\n])
- Group 1: any whitespace but \r
and \n
\}\n
- a }
and any line break (that is how \n
works in VSCode regex search field)[^\S\r\n]*
- any 0 or more whitespaces but \r
and \n
else
- a word else
[^\S\r\n]*
- any 0 or more whitespaces but \r
and \n
\{
- a {
char.Demo:
Upvotes: 1