KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Consider the following example: > testLines <- c("I don't want to match this","This is what I want to match") > grepl('is',testLines) > [1] TRUE TRUE What I want, though, is to only match 'is' when it stands alone as a single word. From reading a bit of perl documentation, it seemed that the way to do this is with \b, an anchor that can be used to identify what comes before and after the patter, i.e. \bword\b matches 'word' but not 'sword'. So I tried the following example, with use of Perl syntax set to 'TRUE': > grepl('\bis\b',testLines,perl=TRUE) > [1] FALSE FALSE The output I'm looking for is FALSE TRUE .
Tags (comma-separated)
Save Edits
Cancel