2014-05-04 61 views
0

我正在嘗試在兩個完整句號(句點)之間找到句子。我嘗試了下面的表達式,但是這似乎忽略了每個替代句子。scala正則表達式 - 在句點字符之間找到句子

"\\..+?\\.".r.findAllIn("''Super Ducktales'' is an [[Ducktales]]'s episode. ==Plot== ===Part 1:Liquid assetats=== When the Ma Beagle's birthday is next, the Beagles sabote the new Duckburg's freeway plant to make that the freeeway pass '''acroos''' the Money Bin. After discovery it, [[Scrooge McDuck]] goes talk with the pig major but he can't accept chenge the plant. After, at [[Manor McDuck]], Scrooge realize that he need contract a accounter.").foreach(println(_)) 

輸出是:

. ==Plot== ===Part 1:Liquid assetats=== When the Ma Beagle's birthday is next, the Beagles sabote the new Duckburg's freeway plant to make that the freeeway pass '''acroos''' the Money Bin. 
. After, at [[Manor McDuck]], Scrooge realize that he need contract a accounter. 

作爲此問題的一個第二部分,我也想提取第一句子也。有什麼辦法可以加入^符號嗎?斯卡拉的

知識是相當有限

回答

1

這是因爲正則表達式消耗,因爲它一起移動。做到這一點,而不是:

"\\.[^.]+"

+0

謝謝,這幫助了,任何方式提取的第一句話也未在fullstops之間圍成的正則表達式? –

+1

'「」「(^ [^。] + | \。[^。] +)」「」。r' – hwnd

+1

或者是'split'「」\。「」「''對吧? –