Regex: Add string in front of paragraph and after it
-
I have several html files, with the same problem. I have 2 ore more paragraphs, and only the first one does not have the html class:
<p class="mb-40px"></p>
So I need to make a regex that can find the paragraph without class and put it.++++++
The choice of this position of the Broadcasting Company as the host of the project was made taking into account the fact that its audience is predominantly young.
<p class="mb-40px">Let me tell you something from the time I lived in the beautiful city of Querétaro, the state capital of the same name in Mexico. First of all, let me give you some useful explanations.</p>
++++++The Output:
<p class="mb-40px">The choice of this position of the Romanian Broadcasting Company as the host of the project was made taking into account the fact that its audience is predominantly young.</p>
<p class="mb-40px">Let me tell you something from the time I lived in the beautiful city of Querétaro, the state capital of the same name in Mexico. First of all, let me give you some useful explanations.</p>
Is it possible? I really don’t know how to do this.
-
@neculai-i-fantanaru said in Regex: Add string in front of paragraph and after it:
Is it possible?
Yes it’s possible.
I really don’t know how to do this.
Then you should probably start learning regex on your own. In your 15 topics in this forum, at least 13 have “search” or “find” or “regex” in the name. This is your fourth new “give me a regex” request in about one week. That seems rather excessive, and is stretching the generousity of the forum members. We are not a free regex writing service. Regex is just one of the many great features of Notepad++, but it’s not overly interesting to answer a billion regex questions, since regex isn’t overly unique to Notepad++. Any text editor worth the name has regex or equivalent power, and if you want to do any fancy search/replace, you eventually have to choose to learn it on your own, rather than depending on free gifts from strangers.
If you read in the FAQ, you will notice that one or two freebies are reasonable before we start requesting that you put in some research yourself. Asking for four in the same week is really stretching things.
If I were trying to solve this problem, I would start my regex by looking for a way to to search for a line that doesn’t start with
<p
… if so, I would put in<p class="mb-40px">
at the beginning. Then I would search for lines that don’t end with</p>
, and if found, append that string.Or maybe combine it into one, by looking for lines that have neither, and wrapping it around.
Concepts that you will have to explore in order to solve this:
- negative lookaheads and negative lookbehinds – this helps you find how to match things that do NOT contain XXX
- beginning of line and end of line anchors
- including the contents of the match in the substitution – hint,
$0
gives the full matched text. - using
.*?
to include a long sequence of variable text in your match:.
here*?
here
But since I haven’t answered your regex-specific questions yet, I will tell that you can use one of Notepad++'s default pluigins to decode the following, which will give you an answer… but it will be more satisfying, and more beneficial for you, if you instead try to develop the regex on your own
T25lIHBvc3NpYmxlIHNvbHV0aW9uOg0KRklORCAgICBeKD8hPHApLis/KD88ITwvcD4pJA0KUkVQTEFDRSA8cCBjbGFzcz0ibWItNDBweCI+JDA8L3A+DQo
Good luck.
----
Useful References
-
Hello, @neculai-i-fantanaru, @peterjones and All,
An other solution even more restrictive :
QW4gb3RoZXIgc29sdXRpb24gZXZlbiBtb3JlIFJFU1RSSUNUSVZFIDoNCg0KU0VBUkNIICAgXltePC8+XHJcbl0rJA0KDQpSRVBMQUNFICA8cCBjbGFzcz0ibWItNDBweCI+JDA8L3A+DQoNClNlZSB0aGUgRElGRkVSRU5DRSB3aXRoIHRoaXMgSU5QVVQgZXhhbXBsZSB0ZXh0IDoNCg0KPHAgY2xhc3M9Im1iLTQwcHgiPkxldCBtZSB0ZWxsIHlvdSBzb21ldGhpbmcgZnJvbSB0aGUgdGltZSBJIGxpdmVkIGluIHRoZSBiZWF1dGlmdWwgY2l0eSBvZiBRdWVyw6l0YXJvLCB0aGUgc3RhdGUgY2FwaXRhbCBvZiB0aGUgc2FtZSBuYW1lIGluIE1leGljby4gRmlyc3Qgb2YgYWxsLCBsZXQgbWUgZ2l2ZSB5b3Ugc29tZSB1c2VmdWwgZXhwbGFuYXRpb25zLjwvcD4NCg0KVGhlIGNob2ljZSBvZiB0aGlzIHBvc2l0aW9uIG9mIHRoZSBCcm9hZGNhc3RpbmcgQ29tcGFueSBhcyB0aGUgaG9zdCBvZiB0aGUgcHJvamVjdCB3YXMgbWFkZSB0YWtpbmcgaW50byBhY2NvdW50IHRoZSBmYWN0IHRoYXQgaXRzIGF1ZGllbmNlIGlzIHByZWRvbWluYW50bHkgeW91bmcuDQoNCjx0ZXN0PkxldCBtZSB0ZWxsIHlvdSBzb21ldGhpbmcgZnJvbSB0aGUgdGltZSBJIGxpdmVkIGluIHRoZSBiZWF1dGlmdWwgY2l0eSBvZiBRdWVyw6l0YXJvLCB0aGUgc3RhdGUgY2FwaXRhbCBvZiB0aGUgc2FtZSBuYW1lIGluIE1leGljby4gRmlyc3Qgb2YgYWxsLCBsZXQgbWUgZ2l2ZSB5b3Ugc29tZSB1c2VmdWwgZXhwbGFuYXRpb25zLjwvdGVzdD4NCg0KVGhlIGNob2ljZSBvZiB0aGlzIHBvc2l0aW9uIG9mIHRoZSBCcm9hZGNhc3RpbmcgQ29tcGFueSBhcyB0aGUgaG9zdCBvZiB0aGUgcHJvamVjdCB3YXMgbWFkZSB0YWtpbmcgaW50byBhY2NvdW50IHRoZSBmYWN0IHRoYXQgaXRzIGF1ZGllbmNlIGlzIHByZWRvbWluYW50bHkgeW91bmcuDQoNCjxwIGNsYXNzPSJtYi00MHB4Ij5MZXQgbWUgdGVsbCB5b3Ugc29tZXRoaW5nIGZyb20gdGhlIHRpbWUgSSBsaXZlZCBpbiB0aGUgYmVhdXRpZnVsIGNpdHkgb2YgUXVlcsOpdGFybywgdGhlIHN0YXRlIGNhcGl0YWwgb2YgdGhlIHNhbWUgbmFtZSBpbiBNZXhpY28uIEZpcnN0IG9mIGFsbCwgbGV0IG1lIGdpdmUgeW91IHNvbWUgdXNlZnVsIGV4cGxhbmF0aW9ucy48L3A+DQo
Best Regards,
guy038
-
FIRST CASE: (if the first line is at the beginning of the file)
FIND:
(?s-i)(\A.*?)(\w+)(.*?)?(\.)([\s\S]*?)(<p class="mb-40px">)
REPLACE BY:
\1<p class="mb-40px">\2\3\4\5</p>\n\6
SECOND CASE: (if the first line is not at the beginning of the file)
FIND:
(START-WORD)([\s\S]*?)(\w+)(.*?)?(\.)([\s\S]*?)(<p class="mb-40px">)
REPLACE BY:
\1\2<p class="mb-40px">\3\4\5\6</p>\n\7
where
START-WORD is the point where you want to start the search
-
@guy038 @PeterJones what are those black line with characters and numbers? Are those short links? I cannot open. I copy and paste on browser, and nothing happens.
-
@robin-cruise said in Regex: Add string in front of paragraph and after it:
what are those black line with characters and numbers? Are those short links? I cannot open. I copy and paste on browser, and nothing happens.
They are providing solutions for you, if you are smart enough to figure out the mechanism they are using. They are making you “work” for it.
-
I see from Alan’s response that you have joined this particular conversation. I now must ask, is @Neculai-I-Fantanaru another one of your alternate accounts, like @rodica-F is? If so, then I will go back to our gentlemen’s agreement from earlier on that I will not try to help you, because neither one of us gets anything out of me helping you (except frustration). But I need to have a complete list of your aliases on this forum if I am to be able to honor that agreement.
Regardless of whether or not you are the same person, maybe @Neculai-I-Fantanaru needs more of a hint on this one:
what are those black line with characters and numbers?
As I told @Neculai-I-Fantanaru already, “I will tell that you can use one of Notepad++'s default pluigins to decode the following, which will give you an answer…”.
By default, Notepad++ comes with three plugins when installed: MIME Tools, Converter, and NppExport. One or more of those plugins comes with at least one action that has “Decode” in the name. One such action in those Plugin menus will decode the string of characters, so if @Neculai-I-Fantanaru were to paste the text from the black box into Notepad++, then use those “decode” actions until the text is decoded into something meaningful, then they would get an answer the original question. But it’s obfuscated in this way, because after so many questions of a similar vein (asking for lots of regex help) from the same user, without that user ever showing any effort or willingness to learn, and expecting us to hand them solutions on a silver platter every time, then I switch tactics: I generally start in helpful tutor/teacher mode (though this time, I just allowed the other Community’s help to serve as that mode); when that shows no benefit in the end user, I switch to puzzle-poser (so I give the answer, but with some barrier to entry) – but this is just a brief one-or-two-attempt stage on my part; if the end user still doesn’t show a willingness to learn, I part ways with that user, because there’s no point in my trying to help someone who wants to treat me as a robot servant rather than as someone who can help them learn.
For everyone reading this thread: if you want to learn regular expressions, great! That will help you get the most out of Notepad++. But you have to actually be willing to learn regular expressions – and that does not mean “demand that the Notepad++ Community hand me a regular expression every time I have a new data problem”. That means learn from the regex you have seen in this forum, learn what the pieces do, study the documentation that you are linked to, and try lots of things. When answering questions in this forum, I often have to spend many iterations getting the regex to do what I want and what I think the end user wants, even though I have a good idea of what most of the individual regex components are supposed to do – this is because regular expressions take effort.
-
LOL. Thanks. I learned how to use one of NPP’s default plugins just now, neat. I’ve not been much of a user of that type of thing so it was a nice side trip. :)
-
@PeterJones thanks. I understand now the DECODE.
Notepad++ -> Menu -> Plugins -> Mime Tools -> Base64 Decode
Thanks for solution @guy038