How to extract expression matching an email address in a text file using R or Command Line?

后端 未结 3 1997
情歌与酒
情歌与酒 2020-12-18 12:18

I have a text file that contains email addresses and some information.

I would like to know how can I extract those email address using R or the terminal?

I\

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-18 13:02

    Read your file into R and use grep.

    myText <- readLines("your.file")
    Emails <- grep("^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,4})$", myText, value=T)
    

    This will return the whole line that the email appears on, if there is other information on that line you will need to split it up first using something like strsplit

提交回复
热议问题