troubleshooting Question

Regular expression substitution drops text before the match.

Avatar of tymccoy
tymccoy asked on
C#Regular Expressions
1 Comment1 Solution11 ViewsLast Modified:

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
gr8gonzo
Consultant

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros