Search code examples
rstringlistvectorexpression

exclude dot with regular expression in R


i got a string vector from list.files() in R and want to exclude the strings with dot (.). the codes are as follows

list.files(R.home(),pattern='[^\\.]') 
list.files(R.home(),pattern='[^.]')

they all don't work. any help is appreciated!


Solution

  • consider using:

     list.files(pattern = "^[^.]+$")
    

    This ensures there is no . from the beginning to the end of the string.