我需要找到所有與「and」字連接的單詞對。scala:獲取正則表達式的所有可能匹配項
到目前爲止,我有以下嘗試:
val salute = """.*?(\w+\W+)and(\W+\w+).*""".r
val salute(a,b) = "hello ladies and gentlemen, mesdames and messieurs, how are you?"
a: String = "ladies "
b: String = " gentlemen"
現在,我想是這樣的:
salute.findAllMatches("hello ladies and gentlemen, mesdames and messieurs, how are you?")
List[(java.lang.String, java.lang.String)] = List((ladies,gentlemen), (mesdames,mesieurs))
我
salute.findAllIn("hello ladies and gentlemen, mesdames and messieurs, how are you?").toList
res14: List[String] = List(hello ladies and gentlemen, mesdames and messieurs, how are you?)
嘗試,但,你可以看,沒有成功...
......這是'Mesdames等Messieurs',順便... –