I need a regular expression to substitute pseudo html in .NET
I have texts like this one:
this is a text in [lang lang="en" ]english[/lang] or a text in [lang lang="en" ]spanish[/lang]
I need to substitute them for:
this is a text in <span lang="en">english </span> or a text in <span lang="es">spanish</span>
I need a regular ex开发者_JAVA百科pression, not a simple replace. The languages in the lang tag can be whatever.
Regex:
\[lang lang="([^"]*)" \](.*?)\[/lang\]
Replacement:
<span lang="$1">$2 </span>
You could simply replace [/lang]
with </span>
and use
Regex.Replace(text, @"\[lang lang=""(\w+)""\]", "<span lang=\"$1\">")
to replace the opening tag.
精彩评论