Copying sentences and pasting them elsewhere
-
I want to copy the sentences at the bottom, starting with
<p................>You
except the last sentence (which doesn’t begin with<p................>You
) and add them between the first<h2.........>
and last</h2>
<h2 style="font-family: "verdana"; font-size: 18px; color: black;">The licenses for most software are designed to take away your freedom to share and change it.</h2> <h2 style="font-family: "verdana"; font-size: 18px; color: black;"> style="font-family: "verdana"; font-size: 18px; color: black;">By contrast, the GNU General Public License is intended to guarantee your freedom to share</h2> <h2 style="font-family: "verdana"; font-size: 18px; color: black;">and change free software--to make sure the software is free for all its users.</h2> <h2 style="font-family: "verdana"; font-size: 18px; color: black;">This General Public License applies to most of the Free Software Foundation's software</h2> <h2 style="font-family: "verdana"; font-size: 18px; color: black;">>and to any other program whose authors commit to using it.</h2> <p>(Some other Free Software Foundation software is covered by the GNU Library General</p> <p>Public License instead) You can apply it to your programs, too.</p> <p>When we speak of free software, we are referring to freedom, not price.</p> <p style="font-family: "verdana"; font-size: 18px; color: black;">Our General Public Licenses are designed to make sure that you have the freedom to distribute</p> <p style="font-family: "verdana"; font-size: 18px; color: black;">copies of free software (and charge for this service if you wish), that you receive source code</p> <p style="font-family: "verdana"; font-size: 18px; color: black;">or can get it if you want it, that you can change the software or use pieces of it in new</p> <p style="font-family: "verdana"; font-size: 18px; color: black;">free programs; and that you know you can do these things.</p> <p style="font-family: "verdana"; font-size: 18px; color: black;">To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights.</p> <p style="font-family: "verdana"; font-size: 18px; color: black;">These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it.</p> <p style="font-family: "verdana"; font-size: 18px; color: black;">For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have.</p> <p>You must make sure that they, too, receive or can get the source code ?</p> <p style="font-family: "verdana"; font-size: 18px; color: black;">You must show them these terms so theyp know their rights?</p> <p style="font-family: "verdana"; font-size: 18px; color: black;">You protect your rights with two steps: (1) copyright the software, and (2) offer you this ?</p> <p style="font-family: "verdana"; font-size: 18px; color: black;">You license which gives you legal permission to copy, distribute and/or modify the software ?</p> <p style="font-family: "verdana"; font-size: 18px; color: black;">You also, for each author's protection and ours, we want to make certain that ?</p> <p style="font-family: "verdana"; font-size: 18px; color: black;">You and everyone understands that there is no warranty for this free software ?</p> <p style="font-family: "verdana"; font-size: 18px; color: black;">You may do so but if the software is modified by someone else and passed on, we want its recipients to know that what they have ?</p> <p style="font-family: "verdana"; font-size: 18px; color: black;">is not the original, so that any problems introduced by others will not reflect on the original authors' reputations.</p>
-
@guy038 @PeterJones @mkupper @Terry R and All, Even if you give me a hint, I will be happy.
-
@dr-ramaanand The final output should be:-
<h2 style="font-family: "verdana"; font-size: 18px; color: black;">You must make sure that they, too, receive or can get the source code ?</p> <p style="font-family: "verdana"; font-size: 18px; color: black;">You must show them these terms so theyp know their rights?</p> <p style="font-family: "verdana"; font-size: 18px; color: black;">You protect your rights with two steps: (1) copyright the software, and (2) offer you this ?</p> <p style="font-family: "verdana"; font-size: 18px; color: black;">You license which gives you legal permission to copy, distribute and/or modify the software ?</p> <p style="font-family: "verdana"; font-size: 18px; color: black;">You also, for each author's protection and ours, we want to make certain that ?</p> <p style="font-family: "verdana"; font-size: 18px; color: black;">You and everyone understands that there is no warranty for this free software ?</p> <p style="font-family: "verdana"; font-size: 18px; color: black;">You may do so but if the software is modified by someone else and passed on, we want its recipients to know that what they have ?</h2> <p>(Some other Free Software Foundation software is covered by the GNU Library General</p> <p>Public License instead) You can apply it to your programs, too.</p> <p>When we speak of free software, we are referring to freedom, not price.</p> <p style="font-family: "verdana"; font-size: 18px; color: black;">Our General Public Licenses are designed to make sure that you have the freedom to distribute</p> <p style="font-family: "verdana"; font-size: 18px; color: black;">copies of free software (and charge for this service if you wish), that you receive source code</p> <p style="font-family: "verdana"; font-size: 18px; color: black;">or can get it if you want it, that you can change the software or use pieces of it in new</p> <p style="font-family: "verdana"; font-size: 18px; color: black;">free programs; and that you know you can do these things.</p> <p style="font-family: "verdana"; font-size: 18px; color: black;">To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights.</p> <p style="font-family: "verdana"; font-size: 18px; color: black;">These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it.</p> <p style="font-family: "verdana"; font-size: 18px; color: black;">For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have.</p> <p>You must make sure that they, too, receive or can get the source code ?</p> <p style="font-family: "verdana"; font-size: 18px; color: black;">You must show them these terms so theyp know their rights?</p> <p style="font-family: "verdana"; font-size: 18px; color: black;">You protect your rights with two steps: (1) copyright the software, and (2) offer you this ?</p> <p style="font-family: "verdana"; font-size: 18px; color: black;">You license which gives you legal permission to copy, distribute and/or modify the software ?</p> <p style="font-family: "verdana"; font-size: 18px; color: black;">You also, for each author's protection and ours, we want to make certain that ?</p> <p style="font-family: "verdana"; font-size: 18px; color: black;">You and everyone understands that there is no warranty for this free software ?</p> <p style="font-family: "verdana"; font-size: 18px; color: black;">You may do so but if the software is modified by someone else and passed on, we want its recipients to know that what they have ?</p> <p style="font-family: "verdana"; font-size: 18px; color: black;">is not the original, so that any problems introduced by others will not reflect on the original authors' reputations.</p>
-
@dr-ramaanand It’s usually much easier to do things as simple search and replace operations. If you have
abc
in many files and now wantxyz
in those files then search forabc
and replace it withxyz
.For example, search for
<h2 style="font-family: "verdana"; font-size: 18px; color: black;">The licenses for most software are designed to take away your freedom to share and change it.</h2>
Replace it with<h2 style="font-family: "verdana"; font-size: 18px; color: black;">You must make sure that they, too, receive or can get the source code ?</p>
Keep repeating until you get the final desired result.
While it’s possible to construct a regular expression that finds information from far down in a file and copies it into a spot that’s higher up in the file it’s going to be a rather specialized expression that may only work well in a few cases. It’s also going to be an expression that is complicated enough that it’s not easy to adapt to similar situations. For example, we don’t know how many other blocks of text you have in your files that are structured in very similar the snippets you posted here. Bulk search/replace operations need to get tuned to make sure then don’t accidentally make unintended changes.
That’s why I say to keep the search replace simple, so that you can understand what is happening and why.
-
@mkupper I have multiple files to do this in. Anyway, someone at www.regex101.com gave me a solution which is working perfectly on Notepad++. I was told to put
<h2[^<>]++>\K(?>.*?</h2>\s*<h2[^<>]*+>)+.*?(?=</h2>)(?=[\S\s]"?<p>([^<>]++)(</p>\s*<p[^<>]++>You[^<>]*+(?2)*+))
in the Find what field,$1$2
in the Replace with field, tick the Regular expression mode and hit Replace all -
@mkupper if there was no “
<p>
” anywhere, I was supposed to use this in the Replace field with the Regular expression ticked:<h2[^<>]++>\K(?>.*?</h2>\s*<h2[^<>]*+>)+.*?(?=</h2>) (?=[\S\s]*? <p[^<>]*+>(You[^<>]++) (</p>\s*<p[^<>]++>You[^<>]*+(?2)*+) )
-
I’d probably use BeautifulSoup for something like this, although that may not help if you don’t know Python.
-
@dr-ramaanand said in Copying sentences and pasting them elsewhere:
if there was no “
<p>
” anywhereBy this, I meant that if instead of
<p>
it is<p style="font-family: "verdana"; font-size: 18px; color: black;">
-
@dr-ramaanand said in Copying sentences and pasting them elsewhere:
<h2[^<>]++>\K(?>.?</h2>\s<h2[^<>]+>)+.?(?=</h2>) (?=[\S\s]? <p[^<>]+>(You[^<>]++) (</p>\s*<p[^<>]++>You[^<>]+(?2)+) )There seem to be some extra spaces in that. The correct Regular expression to use is, “
<h2[^<>]++>\K(?>.*?</h2>\s*<h2[^<>]*+>)+.*?(?=</h2>)(?=[\S\s]*?<p[^<>]*+>(You[^<>]++)(</p>\s*<p[^<>]++>You[^<>]*+(?2)*+))
”
The explanation for something similar can be read at https://community.notepad-plus-plus.org/topic/25210/how-to-replace-strings-involving-search-of-multiple-lines\K
resets the starting point of the reported match. Any previously consumed characters are no longer included in the final match. To make the explanation short, consider the following simple Regex: a\Kb. When “b” is matched, \K tells the Regex engine to pretend that the match attempt started at this position.\s*
is to find any number of whitespace characters[\s\S]
is to find a character class of white-space characters and non-whitespace characters matching any character including a newline - so, it will match anything, followed by what is searched for next. -
@dr-ramaanand said in Copying sentences and pasting them elsewhere:
<p[^<>]*+>(You[^<>]++)(</p>
finds
<p................. >You................. </p>