如何从句子中获得精确的单引号词?

时间:2018-03-07 06:27:59

标签: r regex

我有以下文字。

sent = c("circle took away the victim's soul and supposedly made it easier for him to accept death; it was the point of no return in the vory death ceremony.",
   "hard to see, but he's basically yelling and telling people do not accept these biscuits because they're no good. UNIDENTIFIED-MALE: They are very concerned",
   "the Christ's death, Cambodians can inflict that fate on me, I will accept it.", "Related: What to read about the Khmer RougeKhmer Rouge executioner found")

我的输出应该是

victim's
he's
they're
Christ'

1 个答案:

答案 0 :(得分:1)

希望这有帮助!

m <- gregexpr("[A-Za-z]+'[A-Za-z]+", sent, perl=T)
regmatches(sent, m)

示例数据:

sent = c("circle took away the victim's soul and supposedly made it easier for him to accept death; it was the point of no return in the vory death ceremony.",
         "hard to see, but he's basically yelling and telling people do not accept these biscuits because they're no good. UNIDENTIFIED-MALE: They are very concerned",
         "the Christ's death, Cambodians can inflict that fate on me, I will accept it.", "Related: What to read about the Khmer RougeKhmer Rouge executioner found")