-2

I want to do a Regex.Replace() to get rid of all the \r\n between the ul and /ul tags. Now I love writing RegEx as much as the next guy, But I can't for the life of me figure out the correct pattern to use. Any one have any idea what the pattern I need to match all instances of /r/n between the two tags using RegEx?

This is a note&nbsp;I am using to display bullets&nbsp;here are some examples\r\n<ul>\r\n<li>somethign</li>\r\n<li>somthing else</li>\r\n</ul>
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
JSON
  • 1,113
  • 10
  • 24

1 Answers1

1

There's probably a way to accomplish this is a pure regular expression, but one option is to use a regex and a custom match evaluator:

value = Regex.Replace(value, "<ul>.*?</ul>", (match) =>
    {
        return match.Value.Replace("\r\n", "");
    }, RegexOptions.Singleline);

And as a side point: Once you start thinking about parsing HTML fragments, you should consider using HtmlAgilityPack. It's not always necessary, but it can save trouble as you get more and more complex requirements.

Anon Coward
  • 9,784
  • 3
  • 26
  • 37
  • I like your style. I tried something similar to this but it seems the singleline option is key. Thanks my friend, you made my life easier – JSON Jul 13 '16 at 21:02