 <p>Use word boundary <code>\b</code> which matches a between a word and non-word character,</p> <pre><code>&gt; string = c("apple", "apples", "applez") &gt; grep("\\bapple\\b", string) [1] 1 </code></pre> <p><strong>OR</strong></p> <p>Use anchors. <code>^</code> Asserts that we are at the start. <code>$</code> Asserts that we are at the end.</p> <pre><code>&gt; grep("^apple$", string) [1] 1 </code></pre> <p>You could store the regex inside a variable and then use it like below.</p> <pre><code>&gt; pat &lt;- "\\bapple\\b" &gt; grep(pat, string) [1] 1 &gt; pat &lt;- "^apple$" &gt; grep(pat, string) [1] 1 </code></pre> <p>Update:</p> <pre><code>&gt; paste("^",pat,"$", sep="") [1] "^apple$" &gt; string [1] "apple" "apple:s" "applez" &gt; pat [1] "apple" &gt; grep(paste("^",pat,"$", sep=""), string) [1] 1 </code></pre>