How to find and select all words between select words?
-
@Dawn-Brockman said in How to find and select all words between select words?:
is there a way to select all the text between <plot> and </plot> automatically
There is a method, it involves using “regular expressions”, or regex for short.
So once the file is opened in Notepad++, use the Find function. Set search mode to regular expression and use the following.
Find What:(?s)(?<=plot>)(.+?)(?=</plot>)
click on the Find Next button. The text you want is highlighted.If you need an explanation of the syntax of the regex:
(?s)
… Identifies any DOT character as also containing the line feed characters (\r and \n)
(?<=plot>)
… This positions the cursor so the preceding characters areplot>
(.+?)
… This means grab characters lazily until … (The DOT character means any character)
(?=</plot>)
… we see immediately ahead of us the</plot>
sequence.Terry
-
This did the trick and I was wondering if there was a way to select it and not just highlight it. I do see it all grayed out but I was wondering if there is a easier way then to Hold Shift and then Left Click the text I want to select.
-
@Dawn-Brockman said in How to find and select all words between select words?:
I do see it all grayed out but I was wondering if there is a easier way then to Hold Shift and then Left Click the text I want to select.
Sorry, I don’t know if you mean this to be a new question or follow on from previous.
So once it is highlighted close the Find window and then press Ctrl-C (this will pickup the highlighted text). Go to a new tab or file and position the cursor before Ctrl-V (paste).
Understand it will retain the line formatting as previous, so if multiple lines in the original, then the copy will look exactly the same with indents, line feeds etc.
Terry
-
Okay now finding the “Plot” area is much easier then before and I didn’t know that once the text was highlighted I didn’t need to re-highlight it again once I found the text.
I have been using Ctrl+c and Ctrl+v for a while now I just thought I need to re-select it and then copy it and then paste it. But knowing that by finding it its already highlighted and selected for me. Once I actually copy it with Ctrl+c it gets much easier.
thank you for all the help with this. Now all I need to do is copy the shortcut you gave me and place it into a file and keep it onto my desktop. Do you know of any other tips like this one. Or of a site with tutorials so I can take some tips and place them into a file and keep it on my PC. So I could have some tips at my finger tips so to speak.
-
@Dawn-Brockman said in How to find and select all words between select words?:
Do you know of any other tips like this one.
Well most of the members who have used Notepad++ (often shortened to NPP) for a while will have methods that they use to help them. Unfortunately there isn’t a repository of these that I’m aware of.
But if you have an issue I would suggest searching on this forum first. If you can’t find an answer just post your question. Most of the members will willingly provide their ideas (and solutions) if they think it will help, as I did.
There is an online manual for NPP and references to regular expressions in the FAQ section, so look there as well.
Terry
-
Hello, @dawn-brockman, @terry-R and All,
May be, I misunderstand something obvious, but there is an easy way to get a list of all the
<plot>•••••</plot>
, at once, in a new file :-
Open the Mark dialog (
Ctrl + M
) -
SEARCH
(?s-i)(?<=<plot>).+?(?=</plot>)
-
Tick the two options
Purge for each search
andWrap around
-
Un-tick all other box options
-
Select the
Regular expression
search mode -
Click on the
Mark All
button
=> The
<plot>•••••</plot>
areas shouild be hightlighted in red !-
Now, click on the
Copy Marked Text
button -
Open a new file (
Ctrl + N
) -
Paste the clipboard contents (
Ctrl + V
)
Voila !
In addition, as you’re currently doing a multi-lines regex search, the
Copy Marked Text
feature automatically inserts a four-dashes separation line (----
) between each occurrence ;-))Best Regards,
guy038
-
-
@guy038 said in How to find and select all words between select words?:
easy way to get a list of all the <plot>•••••</plot>
I interpreted the OP’s request as only 1 instance of the text to be selected in the file.
Terry
-
@Dawn-Brockman said in How to find and select all words between select words?:
Now all I need to do is copy the shortcut you gave me and place it into a file and keep it onto my desktop
Instead of that you could make a macro out of it.
- set up your search but don’t execute it yet (or execute it to test it!)
- leave Find window open
- do Macro menu then Start Recording
- now execute the search you’ve previously set up
- do Macro menu then Stop Recording
- do Macro menu then Save Currently Recorded Macro… and name your macro
Now the name you gave the macro will appear in the lower part of the Macro menu, and you can execute it by selecting it.
-
@Alan-Kilborn The Macro trick worked great thank you. Its like a way to cheat and still not need to re-paste the code every time I change the “Search”. Thank You!
-
Hi! I have a similar problem. I need to extract a part of text between strings:
*** text 1 ***
and
*** text 2 ***
The problem is that text 1 and text 2 is different in each of thousands files.
Another problem is that *** should be interpreted as an actual asterisk not a wildcard. Can someone help? I can also use PowerShell but I don’t know how to write a script :| -
Don’t ask the same question in 2 threads; you asked the same question HERE