Notepad3 icon indicating copy to clipboard operation
Notepad3 copied to clipboard

search/replace regex issue

Open np3fan opened this issue 4 years ago • 4 comments

Using 5.21.227.1

Test: wrap space-separated words with { and }

Search string used: ([^ ]+) Replacement used: {\1} Options set: Regular expression search

Text before replacement:

cats dogs
birds fish

Text after replacement:

{cats} {dogs
birds} {fish}

Expected:

{cats} {dogs}
{birds} {fish}

np3fan avatar Jul 28 '21 19:07 np3fan

Your search string says: "match all characters except blank" one or more times. This means including line-break characters. On turning on Menu -> View -> Show line Endings , you can visualize what is selected (if Mark Occurrences is active). Than you will be able to understand that the result is completely correct. Your expectation needs another search expression, e.g. (\w+)

RaiKoHoff avatar Jul 28 '21 21:07 RaiKoHoff

My apologies, you are correct. Can I blame my expectations on vscode?

In vscode performing this test search/replace produces the (wrong) result. It says there are 4 occurrences and performs 4 replacements. I'd say there's something wrong -- or at least very unusual -- with it.

I then tested against textpad, sublime, notepad++, editpad, and adobe brackets; they all produce the (correct) result, performing 3 replacements. So notepad3 is in good company!

I'll note too that brackets was somewhat unusual: it reported 4 occurrences but then performed 3 replacements (!?).

Thanks for all your work with Notepad3.

np3fan avatar Jul 29 '21 02:07 np3fan

The occurrences (and replacement) counting can be improved!

RaiKoHoff avatar Jul 29 '21 08:07 RaiKoHoff

@np3fan : Please help me to reproduce the "4 occurrences but then performed 3 replacements" by detailed workflow description. Thank you in advance.

RaiKoHoff avatar Jul 30 '21 08:07 RaiKoHoff