开发者

Regex remove everything after <

I have a string that looks like:

 some text <a some text "quote" slash..

I want to remove every开发者_运维技巧thing after the < so the above string will result in:

some text

How do I do that? Do i need to use a regex for that?


<[^<]+> [^<]*(?<removeGroup><[^<]*)<[^<]+> use this regular expression to match and remove unwanted string by using the 'removeGroup' in the match.(in .net)


this is very simple so you don't even need to use regex to do this. You can just use string methods, here's a quick write up in C#:

string str = "some text <a some text \"quote\" slash..";
int index = str.IndexOf("<");
string newstr = str.Substring(0, index);

Console.WriteLine("'{0}'", newstr);  // prints 'some text '
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜