How do I replace two <br> tags?
-
How do I replace two <br> tags?
<p class=MsoNormal style='margin-bottom:12.0pt;line-height:normal'><span style='font-size:13.5pt;font-family:"Verdana","sans-serif";mso-fareast-font-family: "Times New Roman";mso-bidi-font-family:"Times New Roman";color:black; mso-ansi-language:EN-US'>- Excitable, changeable, confusion, hilarious. <br> <br> - Anticipation of failure. <br> <br> - Indifference to pleasurable things. <br> <br> - Fear of going into a crowd. <br> <br> - Anger goes to violence. <br> <br> - Aversion to company. <br> <br> - Guilty mind. </span><span style='font-size:13.5pt;font-family:"Verdana","sans-serif"; mso-fareast-font-family:"Times New Roman";mso-bidi-font-family:"Times New Roman"; mso-ansi-language:EN-US'><o:p></o:p></span></p>
should become
<p class=MsoNormal style='margin-bottom:12.0pt;margin-left:5.75pt;text-indent:-5.75pt;line-height:normal'><span style='font-size:13.5pt;font-family:"Verdana","sans-serif";mso-fareast-font-family: "Times New Roman";mso-bidi-font-family:"Times New Roman";color:black; mso-ansi-language:EN-US'>- Excitable, changeable, confusion, hilarious.</span></p> <p class=MsoNormal style='margin-bottom:12.0pt;margin-left:5.75pt;text-indent:-5.75pt;line-height:normal'><span style='font-size:13.5pt;font-family:"Verdana","sans-serif";mso-fareast-font-family: "Times New Roman";mso-bidi-font-family:"Times New Roman";color:black; mso-ansi-language:EN-US'>- Anticipation of failure. </span></p> <p class=MsoNormal style='margin-bottom:12.0pt;margin-left:5.75pt;text-indent:-5.75pt;line-height:normal'><span style='font-size:13.5pt;font-family:"Verdana","sans-serif";mso-fareast-font-family: "Times New Roman";mso-bidi-font-family:"Times New Roman";color:black; mso-ansi-language:EN-US'>- Indifference to pleasurable things. </span></p> <p class=MsoNormal style='margin-bottom:12.0pt;margin-left:5.75pt;text-indent:-5.75pt;line-height:normal'><span style='font-size:13.5pt;font-family:"Verdana","sans-serif";mso-fareast-font-family: "Times New Roman";mso-bidi-font-family:"Times New Roman";color:black; mso-ansi-language:EN-US'>- Fear of going into a crowd. </span></p> <p class=MsoNormal style='margin-bottom:12.0pt;margin-left:5.75pt;text-indent:-5.75pt;line-height:normal'><span style='font-size:13.5pt;font-family:"Verdana","sans-serif";mso-fareast-font-family: "Times New Roman";mso-bidi-font-family:"Times New Roman";color:black; mso-ansi-language:EN-US'>- Anger goes to violence. </span></p> <p class=MsoNormal style='margin-bottom:12.0pt;margin-left:5.75pt;text-indent:-5.75pt;line-height:normal'><span style='font-size:13.5pt;font-family:"Verdana","sans-serif";mso-fareast-font-family: "Times New Roman";mso-bidi-font-family:"Times New Roman";color:black; mso-ansi-language:EN-US'>- Aversion to company. </span></p> <p class=MsoNormal style='margin-bottom:12.0pt;margin-left:5.75pt;text-indent:-5.75pt;line-height:normal'><span style='font-size:13.5pt;font-family:"Verdana","sans-serif";mso-fareast-font-family: "Times New Roman";mso-bidi-font-family:"Times New Roman";color:black; mso-ansi-language:EN-US'>- Guilty mind. </span></p>
I don’t mind using two different RegExes and doing the “search and replace” twice.
For the very first paragraph (or string), I used(?<=p class=MsoNormal style='margin-bottom:12.0pt;line-height:normal'>)-([^<]*)
in the search field and<p class=MsoNormal style='margin-bottom:12.0pt;margin-left:5.75pt;text-indent:-5.75pt;line-height:normal'><span style='font-size:13.5pt;font-family:"Verdana","sans-serif";mso-fareast-font-family: "Times New Roman";mso-bidi-font-family:"Times New Roman";color:black; mso-ansi-language:EN-US'>-$1</span></p>
in the “replace” field but it did not remove the two<br>
tags.
Likewise, it did not remove the two<br>
tags. for any of the other strings. I used the same matter in the “replace with” field as above and this in the “find” field:^ *-([^<]*)
-
If I use
^ *-([^<br>\R<br>]*)
in the “replace” field, it doesn’t even find everything I want it to and so, the text I’m trying to add gets added somewhere in the middle.
Please help! -
In your first example, the FIND expression never mentions the
<br>
, so it completely doesn’t surprise me that it doesn’t get rid of the two<br>
.In the second, you put the
<br>
inside your negative character class[^...]
, so the regular expression was looknig to match 0 or more characters that weren’t any of the individual characters<
,b
,r
,>
,\R
,<
,b
,r
,>
.it appears to me what you want to do is replace two
<br>
’ with whitespace around them with the end-of-span/end-of-paragraph, then newline, then the start of paragraph, start of span.- FIND =
\s*<br>\s*<br>\s*-
- REPLACE =
</span></p>\r\n<p class=MsoNormal style='margin-bottom:12.0pt;line-height:normal'><span style='font-size:13.5pt;font-family:"Verdana","sans-serif";mso-fareast-font-family:"Times New Roman";mso-bidi-font-family:"Times New Roman";color:black; mso-ansi-language:EN-US'>-
- Search Mode = regular expression
As a non-Notepad+±related suggestion: I would suggest studying more about HTML/XML classes, and trying to apply the styles to the class, rather than individually to each paragraph and span tag, so that you don’t need the style tag on every paragraph, and don’t need the spans at all. Microsoft word-process-to-HTML-or-XML might do it the horrible, inefficient way, but there’s no reason you should follow suit. (
<style> .myClassName { margin... etc } </style> <p class="myClassName">- Excitable, etc</p>\r\n<p class="myClassName">-Anticipation of failure.</p>
– one style tag, and just the class for each paragraph)----
Please note: This Community Forum is not a data transformation service; you should not expect to be able to always say “I have data like X and want it to look like Y” and have us do all the work for you. If you are new to the Forum, and new to regular expressions, we will often give help on the first one or two data-transformation questions, especially if they are well-asked and you show a willingness to learn; and we will point you to the documentation where you can learn how to do the data transformations for yourself in the future. But if you repeatedly ask us to do your work for you, you will find that the patience of usually-helpful Community members wears thin. The best way to learn regular expressions is by experimenting with them yourself, and getting a feel for how they work; having us spoon-feed you the answers without you putting in the effort doesn’t help you in the long term and is uninteresting and annoying for us.
----
Do you want regex search/replace help? Then please be patient and polite, show some effort, and be willing to learn; answer questions and requests for clarification that are made of you. All example text should be marked as literal text using the
</>
toolbar button or manual Markdown syntax. To makeregex in red
(and so they keep their special characters like *), use backticks, like`^.*?blah.*?\z`
. Screenshots can be pasted from the clipboard to your post usingCtrl+V
to show graphical items, but any text should be included as literal text in your post so we can easily copy/paste your data. Show the data you have and the text you want to get from that data; include examples of things that should match and be transformed, and things that don’t match and should be left alone; show edge cases and make sure you examples are as varied as your real data. Show the regex you already tried, and why you thought it should work; tell us what’s wrong with what you do get. Read the official NPP Searching / Regex docs and the forum’s Regular Expression FAQ. If you follow these guidelines, you’re much more likely to get helpful replies that solve your problem in the shortest number of tries. - FIND =
-
@PeterJones OK, thanks a lot
-
@PeterJones or anyone else, Please tell me how to replace
<p class=MsoNormal style='margin-bottom:12.0pt;line-height:normal'><span style='font-size:13.5pt;font-family:"Verdana","sans-serif";mso-fareast-font-family: "Times New Roman";mso-bidi-font-family:"Times New Roman";color:black; mso-ansi-language:EN-US'>-
like what I’ve posted right at the top with<p class="css">-
? -
@Scott-Nielson said in How do I replace two <br> tags?:
Please tell me how to replace
Your first post shows this over several lines. That can make it complicated if you have several lines very similar due to the possible variability of the line breaks. Do you know if there are similar lines?
This regex would find something that started with the first portion of what you are looking for and finish with the first instance of the end portion. Search mode must be regular expression. If you have similar lines you do NOT want to remove, then this would not be the method to use.
Find What:(?s)^<p class=MsoNormal style=.+?mso-ansi-language:EN-US'>-
Replace With:<p class="css">-
Note it expects the line to start at the first character position, if this isn’t correct please advise if there are spaces before the<p
and I can alter the regex.Alternatively if you knew for certain that every instance of the code you are looking for had the line break in exactly the same location you could use normal search mode 4 times, with the find what field containing just 1 line of the code each time. The Replace Field would be empty 3 times and on the 4th time the Replace Field would have the replacement code you want. The only issue here is that it leaves 3 blank lines. These could be removed at any time (Edit, Line Operations, Remove Empty Lines), but are not going to affect the webpage from running if left in.
Terry
-
@Terry-R Thanks a lot! I had leading white spaces in some files and so, I used this in the “Find” field:
(?s)^\s*<p class=MsoNormal style=.+?mso-ansi-language:EN-US'>-