正则表达式,用于查找满足条件的所有单词

时间:2016-10-30 03:18:56

标签: r regex stringr

我正试图在正则表达式上用一本名为 R for Data Science 的书来练习练习。

这个问题我无法解决:

  • 鉴于stringr::words中常用词语的语料库,创建正则表达式,找到所有单词:

    1. 以“y”开头。
    2. 以“x”结尾
    3. 有七个字母或更多。

示例:

sentence <- "I want to extract these - yandx,ynx and yrax,romanav "

# it would be helpful to find how to do these with stringr::str_view() function.

另外,请参考我在R中学习正则表达式的一些好资源。​​

1 个答案:

答案 0 :(得分:0)

这个正则表达式适合你(考虑到你的话不包含标点符号)

(?i)((?:^y[a-z]+x)|(?:^[a-z]{7}[a-z]*$))

您也可以使用Regex101来验证您的正则表达式

相关问题