剛纔看到答案再次被允許。這是我推薦的正則表達式:
^(?<title>[\w\s]*), by (?<author>[\w\s]*)\. \((?<publisher>[\w\s]*), (?<msrp>.*)\.\) (?<description>.*)$
它會給你一個名爲拍攝的上述領域,可以在C#中使用這樣的:
private void Main()
{
string input = "BATTLE HYMN OF THE TIGER MOTHER, by Amy Chua. (Penguin Press, $25.95.) A Chinese-American mother makes a case for strict and demanding parenting";
string pattern = @"^(?<title>[\w\s]*), by (?<author>[\w\s]*)\. \((?<publisher>[\w\s]*), (?<msrp>.*)\.\) (?<description>.*)$";
MatchCollection myMatchCollection = Regex.Matches(input, pattern);
foreach (Match myMatch in myMatchCollection)
{
var title = myMatch.Groups["title"];
var author = myMatch.Groups["author"];
var publisher = myMatch.Groups["publisher"];
var msrp = myMatch.Groups["msrp"];
var description = myMatch.Groups["description"];
}
}
你能提供你想要的正則表達式匹配的樣本輸入和輸出嗎?你需要捕捉任何東西嗎? – Jeff 2011-02-28 22:13:08
'(?這沒有任何意義).'應該可以工作。 –
Mehrdad
2011-02-28 22:13:12
你想要一個正則表達式*,它會做什麼?*你希望將標題,作者,出版者,價格和摘要作爲單獨的字段來捕獲嗎?那麼請說吧。 – 2011-02-28 22:13:41