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 '
精彩评论