zoukankan      html  css  js  c++  java
  • R的grep和grepl

     

    grep(pattern, x, ignore.case = FALSE, perl = FALSE, value = FALSE,

         fixed = FALSE, useBytes = FALSE, invert = FALSE)

      

    grepl(pattern, x, ignore.case = FALSE, perl = FALSE,

          fixed = FALSE, useBytes = FALSE)

     

    参数

    取值说明

    ignore.case

    是否区分大小写

    perl

    是否使用perl规则

    fixed

    是否精确匹配

    value

    FALSE返回对应的索引

    TRUE返回匹配到的结果

    useBytes

    FALSE匹配character-by-character

    TRUE 匹配byte-by-byte

    invert

    FALSE返回匹配到的

    TRUE返回没有被匹配的

     

     

     

     

    > grep("[a-z]", letters)

     [1]  1  2  3  4  5  6  7  8  9 10 11 12

    [13] 13 14 15 16 17 18 19 20 21 22 23 24

    [25] 25 26

    > grep("[a-z]", letters,value = TRUE)

     [1] "a" "b" "c" "d" "e" "f" "g" "h" "i"

    [10] "j" "k" "l" "m" "n" "o" "p" "q" "r"

    [19] "s" "t" "u" "v" "w" "x" "y" "z"

    > txt<-c("Spark","RDD","Scala","MLlib","GraghX")

    > grep("^S.*",txt,value = TRUE)

    [1] "Spark" "Scala"

     

    text<-c("ben@sina.com",

            "kate@sina..com",

            "ka...te@sina.com",

            "kate@sina.12",

            "kate@12.sina.com")

    grep("\w+@[[:alpha:]]+\.[[:alpha:]]+",text,value=TRUE)

  • 相关阅读:
    Nginx
    Nginx & AWStats 安装、配置、使用
    Nginx
    linux
    工作中的 Vim 和 git
    后端
    django
    django
    awk流程控制
    linux系统内置函数
  • 原文地址:https://www.cnblogs.com/wwxbi/p/4614498.html
Copyright © 2011-2022 走看看