开发者

I need a regular expression to substitute pseudo html in .NET

开发者 https://www.devze.com 2022-12-25 23:53 出处:网络
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 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号