Regular expression for new line

I am trying to replace a newline >, but I cannot determine part of the regular expression.

I want:

"<StartTag>"

To replace with:

"<StartTag>\n"

but NOT:

"</EndTag>\n"

When I use tags_string.Replace(">", "\n"), it replaces both.

Can someone help with Regex, so I can use Regex.Replace()instead to handle the EndTag case?

+4
source share
3 answers

You can use the following template to match an open tag:

(<[^/][^>]*>)

Then replace it with $1\n.

Regex.Replace(yourText, @"(<[^/][^>]*>)", "$1\n");
+3
source

Consider ...

string output = Regex.Replace (input, @ "(? <= \ <\ w *)>", @ "> \ n");

0

. var s ="</StartTag>"; s = s.Replace("</StartTag>","</StartTag>\n");

-1

All Articles