开发者

Regex remove everything after <

开发者 https://www.devze.com 2023-02-16 14:36 出处:网络
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:

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

精彩评论

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

关注公众号