2011-03-10 33 views
0

我有一個字符串,它看起來像:正則表達式刪除後一切<

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

我想刪除一切後,<所以上面的字符串將導致:

some text 

我怎樣做那?我需要使用正則表達式嗎?

+0

看來你的問題失去了一些字符,嘗試把「一些文本」的代碼塊 – 2011-03-10 16:59:42

+1

執行''和' '標籤屬於你的字符串還是由於格式錯誤? – 2011-03-10 17:07:51

+0

你使用什麼語言? – 2011-03-11 11:14:08

回答

1

<[^<]+> [^<]*(?<removeGroup><[^<]*)<[^<]+> 使用正則表達式匹配,並通過在比賽中使用「removeGroup」刪除不需要的字符串(在.NET)

0

這是非常簡單的,所以你甚至都不需要使用正則表達式來做這個。你可以只用字符串的方法,這裏有一個快速的寫了在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 ' 
相關問題