R grep with 'AND' logic
<p>I'm working with <code>RJDBC</code> on a server whose maintainers frequently update jar versions. Since <code>RJDBC</code> requires classpaths, this poses a problem when paths break. My situation is fortuitous in that the most current jars will always be in the same directory, but the version numbers will have changed. </p>

<p>I'm trying to use a simple <code>grep</code> function in R to isolate which jar I need based on a regex with some <code>AND</code> logic, however R makes this surprisingly difficult...</p>

<p><a href="https://stackoverflow.com/questions/7597559/grep-in-r-with-a-list-of-patterns">This question</a> demonstrates how <code>grep</code> in R can function with the <code>|</code> operator for OR logic, but I can't seem to find similar AND logic operator.</p>

<p>Here's an example:</p>

<pre><code>## Let's say I have three jars in a directory
jars &lt;- list.files('/the/dir')
&gt; jars
[1] "hive-jdbc-1.1.0-cdh5.4.3-standalone.jar" "hive-jdbc-1.1.0-cdh5.4.3.jar" "jython-standalone-2.5.3.jar" 
</code></pre>

<p>The jar I want is "hive-jdbc-1.1.0-cdh5.4.3-standalone.jar"&mdash;how can I use AND logic in grep to extract it? </p>

<pre><code>## I know that OR logic is supported:
j &lt;- jars[grep('hive-jdbc|standalone', jars)]
&gt; j
[1] "hive-jdbc-1.1.0-cdh5.4.3-standalone.jar" "hive-jdbc-1.1.0-cdh5.4.3.jar" "jython-standalone-2.5.3.jar"

## Would AND logic look like the same format?
&gt; jars[grep('hive-jdbc&amp;standalone', jars)]
character(0)
</code></pre>

<p>Not all-that-surprisingly, that last piece doesn't work... I found a <a href="https://stat545-ubc.github.io/block022_regular-expression.html" rel="nofollow noreferrer">useful, yet non-comprehensive, link</a> for grep in R, but it doesn't show an AND operator. Any thoughts?</p>