Need a copy of the red marked regions, after a "Mark All" operation
-
@Alan-Kilborn Sorry, I have found other similar request in this section but it was already closed. So i just write new.
There is no solution under link You have provided. Requesting or complaining can look very similar … -
@Ryszard-Adamus said in Need a copy marked lines feature:
Requesting or complaining can look very similar
Yes, but requesting right here does you no good so it is complaining by default.
If you really care, you should maybe add to the github discussion and say “YEAH, I really want this feature, too!” -
@PeterJones The regexp solution on that thread was for specific case, not universal. I also use regexp to mark the parts i need to check easily but can’t adapt that solution directly to my case. The python is even worse for me.
-
Hello, @ryszard-adamus and All,
In order to only get the marked ranges, with the red highlighting, you could either :
- Use the Python @scott-sumner’s script https://community.notepad-plus-plus.org/topic/12710/marked-text-manipulation/28
OR
-
Use the following regex S/R :
-
SEARCH
(?s-i).*?(
Your regex)|(?s).*\z
( or(?si).*?(
Your regex)|(?s).*\z
for insensitive to case search ) -
REPLACE
?1\1\r\n
-
This post is an update of this old post https://community.notepad-plus-plus.org/topic/12710/marked-text-manipulation/8
IMPORTANT :
-
Replace the expression Your regex by the
string
, theexpression
or theregex expression
that you would have used, normally, in theMark
dialog -
If you regex contains the dot symbol and tries to match text, in a single line, only, you MUST add the negative modifier
(?-s)
, BEFORE your regex, in order to stop the action of the(?s)
modifier, located at beginning of the overall regex !
NOTES :
-
The first part
(?s-i).*?
matches the shortest range of characters, even null or on multi-lines, till the text that YOUR regex matches -
The second part
(Your regex)
, enclosed in round brackets, is the range of text, matched by YOUR regex, with the exact case, which is stored as group 1 -
The third and final part
|(?s).*\z
is a second alternative, which matches all the remaining text, even null, till the very end of the current file, when the first alternative cannot be matched, anymore ! -
In replacement, if group 1 exists ( first alternative ) this group is re-written, followed by a line break (
\r\n
) -
If group 1 does not exist ( case of the second alternative ), nothing occurs. So, as expected, the remaining text is, then, deleted
EXAMPLE :
-
In the license.txt file, let suppose that you would like to extract all the longest single-line strings, matched by the regex
(a.*j)
, in an insensitive way(?i)
-
Open the
license.txt
file -
Iniitially, you would have marked these ranges of text with the regex, in the Mark dialog :
- SEARCH
(?i-s)a.*j
- SEARCH
-
Go back to the very beginning of your current file ( Ctrl + Home )
-
Open the Replace dialog ( Ctrl + H )
-
SEARCH
(?si)^.*?(?-s)(a.*j)|(?s).*\z
-
REPLACE
?1\1\r\n
-
-
Select the Regular expression search mode
-
Click on the Replace All button
Et voilà !
Note that the @Scott-Sumner’s script and this regex S/R does give exactly the same results ;-))
If you prefer, just tell me about the expression / regex, that you currently use to get your marked ranges and I’ll give your the exact syntax to build, from the generic regex S/R, above
Best Regards,
guy038
P.S. :
You must be aware about
3
points :-
The regex S/R solution, above, is a destructive solution, in the sense that the original contents are lost ! Hence the need to copy the input text to a new tab, first !
-
If your regex, already, contains one or several capturing groups, you MUST increase by ONE the number of each capturing group, used in your OWN search regex, as, in my global regex, I use round brackets to define the first group 1 !!
For instance, let’s suppose that you’re searching all the consecutive duplicate lines, in a sorted file, in order to extract them, leading to the common searched regex
(?-s)^(.+\R)\1+
. Once, inserted in the overall regex, the correct syntax is, therefore :(?s)^.*?((?-s)^(.+\R)\2+)|(?s).*\z
( and NOT(?s)^.\*?((?-s)^(.+\R)\1+)|(?s).\*\z
! )- If your regex matches complete lines, with their EOL characters, you’ll probably change the global replacement to the regex
?1\1
( instead of ?1\1\r\n ), unless you prefer to space any matched expression by a blank line separator !
-
@Ryszard-Adamus said in Need a copy marked lines feature:
The regexp solution on that thread was for specific case, not universal.
@guy038 gives a “universal” solution above.
The python is even worse for me.
Because you don’t want to try it?
The Pythonscript may have an advantage in that if you want to redmark a bunch of different regular expression hits, you can do so, and then when you’re all done, you can run the script and copy ALL of the hits that it took you several marking operations to do.
-
@Ryszard-Adamus said in Need a copy marked lines feature:
The regexp solution on that thread was for specific case, not universal
You read the wrong post then, or misunderstood the post you did read. I didn’t say anything about regex, and neither did the post I linked.
The post I was referring to is https://community.notepad-plus-plus.org/post/24733, which as Guy said could also be linked as https://community.notepad-plus-plus.org/topic/12710/marked-text-manipulation/18, by @Scott-Sumner on
May 31, 2017 at 12:19PM (might be timzone adjusted for you), with the text “So here is RedmarkedTextToClipboard2.py:”, followed by Python code.The script assumes you have already marked your text from the Find > Mark dialog; the script searches the document for all the marked text, and adds all that text into the copy buffer. That’s exactly the procedure you described.
I was about to explain the steps involved in installing PythonScript and running the described script, but …
How Rude
… but now I see you’re running off in a huff, deleting your post. That is poor behavior in any forum anywhere.
-
@PeterJones said in Need a copy marked lines feature:
I see you’re running off in a huff, deleting your post. That is poor behavior in any forum anywhere.
@guy038 , as an admin, should restore the original post for any future readers/searchers?
-
Hello, @Alan-kilborn, @peterjones and All,
I would say that, when running successive mark processes, each method has advantages and drawbacks !
-
The script solution keep the natural order of lines of the file and will be more compact, as a single line is created, in case of overlapping matches of the different regexes !
-
The regex solution does not keep the order of the lines, but better distinguishes the matches of each regex, in case of overlapping matches, as a line is created for each match
Best Regards,
guy038
-
-
Hello, @Alan-kilborn, @peterjones and All,
I don"t know if it would be fair to go against the will of the OP, but but I’ve come up with a compromise :
I changed the intial title
Need a copy marked lines feature
with this new title
Need a copy of the red marked regions, after a "Mark All" operation
BR
guy038
-
in case of overlapping matches
Well, I meant non-overlapping matches of course. Often while marking data it is simpler to come up with 3 or 4 successive marking operations on different data in order to capture everything you want; coming up with one regex, while perhaps an interesting exercise, would likely be distracting from your at-hand task.