简体   繁体   English

C#中的正则表达式(Regex)

[英]Regular Expression (Regex) in C#

how i can Replace those string in C# 我如何在C#中替换这些字符串

I need //cursive// text and //cursive// text.

INTO: 进入:

I need <i>cursive</i> text and <i>cursive</i> text.

AND

This si me [website[http://www.website.com]] and other me [website[http://www.website2.com]].

INTO: 进入:

This si me <a href='http://www.website.com'>website</a> and other me <a href='http://www.website2.com'>website</a>.

Solutiuon for first act: 第一幕的解决方案:

string Test = "Mama ma //hodne// prace protoze //neni// doma.";
string Result = Regex.Replace(Test, "//(.+?)//", "<i>$1</i>");

Solution for second act: 第二幕的解决方案:

string Test2 = "Mama ma [hodne[http://www.someurl.com]]  protoze [neni[http://www.someurl.com]] doma.";
string Result2 = Regex.Replace(Test2, "\\[(.+?)\\[(.+?)\\]\\]", "<a href='$2' target='_blank'>$1</a>");

Solution found by JinDave: JinDave发现的解决方案:

Solutiuon for first act: 第一幕的解决方案:

string Test = "Mama ma //hodne// prace protoze //neni// doma.";
string Result = Regex.Replace(Test, "//(.+?)//", "<i>$1</i>");

Solution for second act: 第二幕的解决方案:

string Test2 = "Mama ma [hodne[http://www.someurl.com]]  protoze [neni[http://www.someurl.com]] doma.";
string Result2 = Regex.Replace(Test2, "\\[(.+?)\\[(.+?)\\]\\]", "<a href='$2' target='_blank'>$1</a>");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM