Feature Request - Textarea search/replace
-
I guess that (unlike @Claudia-Frank and perhaps @guy038) I am unclear on what this capability really provides–it appears to me that it simply allows one to ignore whitespace and linebreaks in the text to be found, and to map what IS found (ws and linebreak structure, and regex replacements obviously) into the replace text? See? The weirdness of my last sentence really expresses how confused I am by this.
However, I’m always seeking a better way to do things, and when people talk about replacements using regex, I’m definitely on-board! So I WANT to understand. Perhaps I will try out Editplus to try and get a real feel for it.
As far as getting substantative changes into native Notepad++, I wouldn’t count on it (it could always be a plugin/script solution…no shame in that…), but I wouldn’t want to discourage you too much for your feature request.
-
Hi Alan,
I didn’t try EditPlus but from the screenshot given I assume
it treats every char as given, even whitespace and eol and
escapes chars if needed but the most benefit I see is that it looks more natural.
If you would have to create a single line regex from the example given,
it would already start getting unreadable.Already thinking how I can include this into my regex tester script. :-)
Cheers
Claudia -
Hi @Alan-Kilborn,
@Claudia-Frank explained it all (thanks for that Claudia), the main feature on this functionality is “it treats every char as given, even whitespace and eol and escapes chars if needed”.
You guys should really try out this EditPlus feature, you can download the evaluation version and test it. Perhaps without a real world scenario for a guy fully familiarized with regex it is hard to imagine the benefits (as we can do it with regex). The main point is that even with knowledge in regex I still lost some time figuring it out, with this feature it would be much simpler, just copy a portion of the needed text and change very few things on it.
It is important to note that it also works without regex so if in a plain text you wan’t to search a word and replace it with a period then an enter, then a tab then some text and another enter, you just put the word on the search box and the paragraph as is (as you want it) in the replace box without need to know regex or even extended characters like \n, \t, \r, etc.
Cheers
-
@Jorge-Campos said:
It is important to note that it also works without regex so if in a plain text you wan’t to search a word and replace it with a period then an enter, then a tab then some text and another enter, you just put the word on the search box and the paragraph as is (as you want it) in the replace box without need to know regex or even extended characters like \n, \t, \r, etc.
That part of the discussion (especially) makes me want to recommend the techniques discussed in this thread (https://notepad-plus-plus.org/community/topic/12973/multiple-line-replacing-doesn-t-work) as a compromise – this is functionality you can have TODAY, albeit not as nice as the aforementioned user interface would be…
-
As I said before, I do know how to do it with Npp. I just would like it to be easier as it is in EditPlus. :)
-
Now that I have the true understanding, I think that @Claudia-Frank 's suggestion of modifying slightly the Python TK-user-interface script she pointed to is a really good one for this.
Or…you can feel really good about having made your feature request…and get annoyed in the coming months/years that your “really great idea” hasn’t “gone native” in Notepad++…especially when you need to do a replace operation that would really benefit from having it. :-D
Cheers!
-
No problem, when I have the time I will try to create it myself. I suppose that I was expecting too much. Thanks for the heads up though.
Cheers
-
@Jorge Campos:
Axiomatic one, I made a similar request in the ‘Help’ forum:https://notepad-plus-plus.org/community/topic/13808/search-replace-of-multiline-text-blocs
“Search/Replace of Multiline Text Blocs”I made a reference to another great freebie:
‘Replace Text’ by Ecobyte. I use it to replace text in hundreds of Web pages at once. It has a special feature: ‘Advanced Edit’. I copy-and-paste blocs of text into ‘Advanced Edit’. It converts the bloc into a one-line string with special characters between the lines in the original bloc to be searched/replaced. No complicated regex coding needed.
If not present, Notepad++ could add such feature to its arsenal. I thought the ‘Extended (\n, r, …)’ search option would do it. It doesn’t work for me! It would be great to perform such a task in Notepad++, instead of exiting and running Ecobyte.
Ion Saliu
“A good man is an axiomatic man; an axiomatic man is a happy man. Be axiomatic!” -
So I discovered, while experimenting with “multiline find” in relation to the original topic of this thread, that it is impossible to successfully “find-all-in-current-document” when your multiline find text includes a literal
\
followed immediately by a literaln
. Note that there are other similar scenarios with the same problem, but to keep this simple I’ll just use this case for discussion.Here’s a test case:
print "hello" + "\n" print "there" + "\n" print "hello" + "\n" print "there" + "\n"
Having the above text in your active editor tab, selecting the first two lines and invoking the find dialog will result in the find-what box appearing like this:
print "hello" + "\n"print "there" + "\n"
Note the unseen line-ending is between the
"
and thep
.At this point, setting normal search-mode and pressing the button for “Find All in Current Docuement” will result in zero hits even though it should result in two. Since no matches are found the Find dialog does NOT automatically close, and at this point it may be noticed that the search-mode has changed from Normal to Extended.
This behavior bothered me, so I dug into the source code to see what was going on. A key part seemed to be extended search mode getting set so I started there. I went to FindReplaceDlg.rc and found that the control ID for that button is
IDEXTENDED
. Searching the remainder of the source for that text, there were few hits (< 10) and the most interesting appeared to be this one:::SendDlgItemMessage(_hSelf, IDEXTENDED, BM_SETCHECK, TRUE, 0);
–the code itself, not the user, is setting the Extended search mode radiobutton.The function (
void FindReplaceDlg::combo2ExtendedMode(int comboID)
) that calls that executes the above SendDlgItemMessage() function is interesting in that it examines the find-what box contents and, if that box contains one or more real line-endings (meaning invocation of the find with multiline selection active), it actually ALTERS the contents, substituting literal\
,r
,\
andn
for any line-ending characters it encounters (note: Windows line endings discussed here; same effect for other types).Ok, so the find-what contents have been altered to contain some literal text with backslashes and r and n in it, and extended search mode has been set, and THEN Notepad++ runs the find-all. Presumably this is done so that line-endings are easier for the code to search for (??), although I don’t see why leaving them as-is and searching literally for the data wouldn’t work fine (as it does for the find-next functionality, where this odd substitution does NOT happen). Most importantly, the code doing this screws up a user intention to search for certain literal backslash sequences, because now these sequences are interpreted specially, not literally!
A search on
combo2ExtendedMode()
shows that it is called when find-all-in-current-doc, find-all-in-opened-files, or find-in-files is executed, so any of these will cause the same effect.So the bottom line is that if you want to select a multiline block of text which contains the literal character sequence equivalents of anything that the Extended search mode thinks of as “escape sequences”, you can’t realistically do those type of searches. Sure, you could painfully edit the find-what box after you select your multiline text and invoke the find dialog, but that rather kills the utility of selecting a big multiline block of data before bringing up the dialog.
I guess I wouldn’t call this behavior a bug per se, I just don’t particularly like the way it works. :(
-
Hello, @scott-sumner and All,
Scott, I investigated this “pseudo” bug and here are my ( non exhaustive ) conclusions !
For an easy reading, click on the
¶
button, of the Tools bar, to visualize all the hidden characters-
First, these weird results exist from a very long time ( Probably from adding the Extented search mode ? ) I was able to reproduce it, with the old v5.9.8 version !
-
Case A
: IF you select any text, WITHOUT including any following End of line character(s) ( NoCR
norLF
chars ), any immediate search, in NORMAL search mode, clicking on the Find All in Current document OR on the Find All in All Opened Documents, work normally ! No problem :-)) -
Case B
: IF you select any text, INCLUDING its End of Line character(s), any immediate search, in NORMAL search mode, clicking on the Find All in Current document OR on the Find All in All Opened Documents, does NOT work properly, if the search includes any of the literal following characters, below, and produces NO result :-((\t
\n
\r
\0
\\
-
Case C
: IF you select any text, INCLUDING its End of Line character(s), which contains escaped characters, except for the five above, any immediate search, in NORMAL search mode, clicking on the Find All in Current document OR on the Find All in All Opened Documents, DOES find result(s), if any ! -
However, note that a bad side-effect of
Case B
ORCase C
searches, is that the search mode is, wrongly, changed fromNormal
toExtended
So, if you, really, need to search for text, containing any of the five literal forms, below, and ending by its End of Line characters :
\t
\n
\r
\0
\\
Just follow the few steps, below :
-
Open the Find dialog (
Ctrl + F
) -
Type the corresponding regexes, below, in the Find what: box
\\t\R
\\n\R
\\r\R
\\0\R
\\\\\R
OR\\{2}\R
-
Check the Regular expression search mode
-
Click on the Find All in Current document OR on the Find All in All Opened Documents button
You may, as well :
-
Select, first, the text, including its End of Line characters
-
Open the Find dialog (
Ctrl + F
) -
In the Find what: field, simply escape, with an other
\
, inserted before, each anti-slash character (\
) -
Check the Regular expression search mode
-
Click on the Find All in Current document OR on the Find All in All Opened Documents button
Best Regards,
guy038
-