繁体   English   中英

如何使用R代码找出句子中的连续单词

[英]How to find out the consecutive word in a sentence using R code

如何使用R代码找出句子中的连续单词。

例如:

有如下所述的句子,它是以下的输出

sentence <- text[grep("Guarantee of",text)]

“你被要求提交13,863.00卢比的性能保证 - (卢比一万三千八百六十三)”

现在我需要得到“保证”的连续字,即“Rs.13,863.00 / - ”

-谢谢

sentence <- 'You are requested to submit the Performance Guarantee of Rs.13,863.00/-( Rupees thirteen thousand and eight sixty three)';
sub('.*Guarantee\\s+of\\s+([a-zA-Z0-9,._/-]+).*','\\1',sentence);
## [1] "Rs.13,863.00/-"

尝试

gsub('.*Guarantee of\\s*|\\(.*', '', str1)
[1] "Rs.13,863.00/-"

要么

library(stringr)
str_extract(str1, '(?:Rs.)[^(]+')
#[1] "Rs.13,863.00/-"

数据

  str1 <- "You are requested to submit the Performance Guarantee of Rs.13,863.00/-( Rupees thirteen thousand and eight sixty three)"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM