【发布时间】:2016-09-18 14:12:41
【问题描述】:
我需要从段落中提取包含单词island 或Island 的句子。每个句子都以大写字母开头,以句点结尾。
段落为字符串
"
The islands were settled from the second century AD by a series of local empires. In 1819, Sir Stamford Raffles founded modern Singapore as a trading post of the East India Company; after the company collapsed, the islands were ceded to Britain and became part of its Straits Settlements in 1826. During World War II, Singapore was occupied by Japan. It gained independence from Britain in 1963, by uniting with other former British territories to form Malaysia, but was expelled two years later over ideological differences. After early years of turbulence, and despite lacking natural resources and a hinterland, the nation developed rapidly as an Asian Tiger economy, based on external trade and its human capital.
"(来源:https://en.wikipedia.org/wiki/Singapore)
作为数组元素的理想结果:
- 这些岛屿从公元 2 世纪开始由一系列地方帝国定居。
- 1819年,斯坦福莱佛士爵士创立现代新加坡,作为东印度公司的贸易站;公司倒闭后,这些岛屿被割让给英国,并于 1826 年成为其海峡殖民地的一部分。
我找到了其他语言的示例,例如 Java (Regex to find sentence containing specific word (java) from paragraph)。但是,同样的 Regex 不适用于 Ruby。
使用 Ruby 可以做到这一点吗?
【问题讨论】: