Link to home
Avatar of tymccoy
tymccoy

asked on

Regular expression substitution drops text before the match.

Trying to use regular expressions in C# to clean up span tags generated by GoogleDoc. The typical line has multiple span tags, and among them are spans that set the font weight to bold. I want to change only those bolding spans, but I am not able to write an expression that skips the content that precedes the bold span.


I know that the problem is that the match is triggered by the first span tag. What is the expression that skips all preceding span tags if they do not include a match of the target font string?


line1 = Regex.Replace(l, "<span style=.*font-weight: bold; .*;\" > ", " <span style='font-weight: bold'>");


line1 becomes this from that regex: 

<span style='font-weight: bold;'>we have created three “Top 10 Restaurant” lists.</span>



This is the original line line1:

<span style="font-size: 12pt; font-family: Calibri, sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" data-mce-style="font-size: 12pt; font-family: Calibri, sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">With over 180 eateries on TCI, it can be tricky to decide where to dine. To make it easier for you to plan where to go, </span><span style="font-size: 12pt; font-family: Calibri, sans-serif; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" data-mce-style="font-size: 12pt; font-family: Calibri, sans-serif; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">we have created three “Top 10 Restaurant” lists.</span>

ASKER CERTIFIED SOLUTION
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial