How to replace a hyphen with some code (which makes the text of the second line come below the text of the first line instead of below the hyphen) using Regex?
-
How to replace a hyphen with some code (which makes the text of the second line come below the text of the first line instead of below the hyphen) using Regex in an HTML file?
This Regex is not working:(?<!^)(?<! )(^-)
- I used the^
so that only the hyphen at the beginning of the sentence is found. If I use(?<!^)(?<! )(-)
it finds all the hyphens which I don’t want to happen.
With HTML, it first is:-<td width=642 valign=top style='width:481.5pt;border:solid #BFDBFF 1.0pt; mso-border-alt:solid #BFDBFF .75pt;padding:3.75pt 3.75pt 3.75pt 3.75pt'> <p class=MsoNormal style='margin-bottom:12.0pt'><span style='font-size: 13.5pt;line-height:115%;font-family:"Verdana","sans-serif";color:black'>-Chilly. COLD SHIVERING AS IF BLOOD WERE ICE-WATER (Acon). <br> <br> -Chill extending up and down back, as if cold water dropped down the spine. <br> <br> -Cold-water feeling between the scapulae (Clarke;K.886). <br> <br> -Sensation of a WET CLOTH ON THE BACK. <br> <br> -Great prostration, wants to lie down all the time. Cold, clammy skin, cold hands. <br> <br> -Faintness. Debility due to malassimilation of food.</span><span style='font-size: 13.5pt;line-height:115%;font-family:"Verdana","sans-serif"'><o:p></o:p></span></p> </td> <td style='padding:3.75pt 3.75pt 3.75pt 3.75pt'></td> </tr>
which I want to become like this:-
<table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2"> <tbody> <tr> <td align="left" valign="top"><span style="color: rgb(0, 0, 0); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">-</span></td> <td align="left" valign="top"><span style="color: rgb(0, 0, 0); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">Chilly. COLD SHIVERING AS IF BLOOD WERE ICE-</span><span style="color: rgb(0, 0, 0); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;"><span style="color: rgb(0, 0, 0); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;"><span style="color: rgb(0, 0, 0); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;"><span style="color: rgb(0, 0, 0); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;"><span style="color: rgb(0, 0, 0); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;"><span style="color: rgb(0, 0, 0); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">WATER (Acon).</span></span></span><span style="color: rgb(0, 0, 0); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">WATER (Acon).</span></span></span></span><span style="color: rgb(0, 0, 0); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;"><span style="color: rgb(0, 0, 0); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;"></span></span><span style="color: rgb(0, 0, 0); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;"><span style="color: rgb(0, 0, 0); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;"></span></span><span style="color: rgb(0, 0, 0); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;"><br> </span></span></td> </tr> </tbody> </table> <br> <span style="color: rgb(0, 0, 0); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;"><br> <table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2"> <tbody> <tr> <td align="left" valign="top"><span style="color: rgb(0, 0, 0); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">-</span></td> <td align="left" valign="top"><span style="color: rgb(0, 0, 0); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">Chill extending up and down back, as if cold water dropped down the spine. </span></td> </tr> </tbody> </table> <br> <br> <table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2"> <tbody> <tr> <td align="left" valign="top"><span style="color: rgb(0, 0, 0); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">-</span></td> <td align="left" valign="top"><span style="color: rgb(0, 0, 0); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;"><span style="color: rgb(0, 0, 0); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;"><span style="color: rgb(0, 0, 0); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">Cold-</span><span style="color: rgb(0, 0, 0); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;"><span style="color: rgb(0, 0, 0); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;"><span style="color: rgb(0, 0, 0); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;"><span style="color: rgb(0, 0, 0); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">water feeling between the scapulae (Clarke;K.886).</span></span></span></span><span style="color: rgb(0, 0, 0); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;"><br> </span></span></span></td> </tr> </tbody> </table> <br> <span style="color: rgb(0, 0, 0); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;"> <table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2"> <tbody> <tr> <td align="left" valign="top"><span style="color: rgb(0, 0, 0); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">-</span></td> <td align="left" valign="top"><span style="color: rgb(0, 0, 0); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">Sensation of a WET CLOTH ON THE BACK. </span></td> </tr> </tbody> </table> <br> <br> <table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2"> <tbody> <tr> <td align="left" valign="top"><span style="color: rgb(0, 0, 0); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">-</span></td> <td align="left" valign="top"><span style="color: rgb(0, 0, 0); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">Great prostration, wants to lie down all the time. Cold, clammy skin, cold hands. </span></td> </tr> </tbody> </table> <br> <br> <table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2"> <tbody> <tr> <td align="left" valign="top"><span style="color: rgb(0, 0, 0); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">-</span></td> <td align="left" valign="top"><span style="color: rgb(0, 0, 0); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">Faintness. Debility due to malassimilation of food. </span></td> </tr> </tbody> </table>
I want a Regex which will help do the replacement in one go instead of me doing things manually, line by line.
Please help! -
@Ramanand-Jhingade Three strings have to added:
<table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2"><tbody><tr><td align="left" valign="top"><span style="color: rgb(0, 0, 0); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">
before the hyphen,</span></td><td align="left" valign="top"><span style="color: rgb(0, 0, 0); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">
after the hyphen and</span></td></tr></tbody></table>
where the text of each line ends (the last line of which is “Faintness. Debility due to malassimilation of food.”) -
@Ramanand-Jhingade …that is, just before the first <br> on each line and just before the </span> on the last line.
-
@Ramanand-Jhingade said in How to replace a hyphen with some code (which makes the text of the second line come below the text of the first line instead of below the hyphen) using Regex?:
If I use (?<!^)(?<! )(-) it finds all the hyphens which I don’t want to happen.
First thought is that
^\x20*-
should find ONLY the hyphen at the start of each line (sentence if you want to call it that as it does seem each sentence starts on a new line).As for the rest, it looks like there is a great deal of repetition with some of the html code. My initial thought would be to convert that code to a special set of characters not found elsewhere, such as
#@#
. So your first regex could be a lot shorter and use these characters. Then a second regex would replace all occurrences of these 3 characters with the real code.Terry
-
@Terry-R said in How to replace a hyphen with some code (which makes the text of the second line come below the text of the first line instead of below the hyphen) using Regex?:
My initial thought would be to convert that code to a special set of characters not found elsewhere, such as #@#.
Part of the reason for splitting the replacement into 2 steps is that you have a lot of replacement text to insert. I haven’t counted the amount but be mindful there is a limit to the number of characters that can be used to find strings and also that which can be replaced. Read the manual here and go down about 3 pages, looking for A valid Find what edit box entry length ranges from 1 to 2046 characters.
Terry
-
@Terry-R I changed all the hyphens that I wanted to change manually to
#@#
and searched for(?<!^)(?<! )(#@#)([^<]*)(?=<br>)
and replaced it with<table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2"><tbody><tr><td align="left" valign="top"><span style="color: rgb\(0, 0, 0\); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">#@#</span></td><td align="left" valign="top"><span style="color: rgb\(0, 0, 0\); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">$1</span></td></tr></tbody></table>
and it worked but I still think it can be done in one step with the right Regex. I think someone needs to help me find the hyphen/s at the beginning of each line for that -
@Ramanand-Jhingade Sorry, I used
<table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2"><tbody><tr><td align="left" valign="top"><span style="color: rgb\(0, 0, 0\); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">#@#</span></td><td align="left" valign="top"><span style="color: rgb\(0, 0, 0\); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">$1$2</span></td></tr></tbody></table>
in the replace field - some typo -
@Ramanand-Jhingade said in How to replace a hyphen with some code (which makes the text of the second line come below the text of the first line instead of below the hyphen) using Regex?:
I think someone needs to help me find the hyphen/s at the beginning of each line for that
The regex I provided should have done that. If not then it would seem you have additional data not shown which affects the ability to target just those hyphens you want to change.
So did you try?:
Find What:^\x20*-([^<])*
Replace With:<table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2"><tbody><tr><td align="left" valign="top"><span style="color: rgb\(0, 0, 0\); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;"></span></td><td align="left" valign="top"><span style="color: rgb\(0, 0, 0\); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">$1</span></td></tr></tbody></table>
because from what I can figure with your latest post that would seem to be the combination of the first replacement and your html code insert. -
@Terry-R Your Regex above finds what it needs to perfectly but the replacement needs to improve as it does not add the text before the <br> back
-
This post is deleted! -
@Terry-R OK, I used this in the replace field:
<table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2"><tbody><tr><td align="left" valign="top"><span style="color: rgb\(0, 0, 0\); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">-</span></td><td align="left" valign="top"><span style="color: rgb\(0, 0, 0\); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">$0</span></td></tr></tbody></table>
and it worked!
Thanks a lot!
However, it adds the 4 spaces and the hyphen that were there originally also - any way I can avoid that (but of course, I want the text to be there after the replacement)? -
@Ramanand-Jhingade said in How to replace a hyphen with some code (which makes the text of the second line come below the text of the first line instead of below the hyphen) using Regex?:
However, it adds the 4 spaces and the hyphen that were there originally also
That’s because you have $0 which means all of the found text. Previously you had $1 which is the correct one.
Terry
-
@Terry-R $1 was not adding back the text after the replacement which is why I used $0. If there is a way to avoid the 4 spaces and hyphen, as well as add the text after the replacement, please let me know. If that is not possible, please tell me how to find the unwanted hyphen, just before the text that I want - I can find only the wanted hyphen with
-[^A-Za-z]
due to my limited knowledge of Regex -
@Terry-R I finally used this Regex in the “Find” field:
^ *-([^<]*)
and this in the “Replace” field and it worked perfectly:<table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2"><tbody><tr><td align="left" valign="top"><span style="color: rgb\(0, 0, 0\); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">-</span></td><td align="left" valign="top"><span style="color: rgb\(0, 0, 0\); font-family: Verdana,sans-serif; font-size: 18px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; display: inline ! important; float: none;">$1</span></td></tr></tbody></table>
Thanks for your time and help! -
@Terry-R The second
*
had to be within the bracket!