R- regex extracting a string between a dash and a period
<p>First of all I apologize if this question is too naive or has been repeated earlier. I tried to find it in the forum but I'm posting it as a question because I failed to find an answer.</p>

<p>I have a data frame with column names as follows;</p>

<pre><code>head(rownames(u))

[1] "A17-R-Null-C-3.AT2G41240"       "A18-R-Null-C-3.AT2G41240"         "B19-R-Null-C-3.AT2G41240"      
[4] "B20-R-Null-C-3.AT2G41240"       "A21-R-Transgenic-C-3.AT2G41240" "A22-R-Transgenic-C-3.AT2G41240"
</code></pre>

<p>What I want is to use regex in R to extract the string in between the first dash and the last period.</p>

<p>Anticipated results are,</p>

<pre><code>[1] "R-Null-C-3"       "R-Null-C-3"         "R-Null-C-3"      
[4] "R-Null-C-3"       "R-Transgenic-C-3" "R-Transgenic-C-3"
</code></pre>

<p>I tried following with no luck...</p>

<pre><code>gsub("^[^-]*-|.+\\.","\\2", rownames(u))
gsub("^.+-","", rownames(u))
sub("^[^-]*.|\\..","", rownames(u))
</code></pre>

<p>Would someone be able to help me with this problem?</p>

<p>Thanks a lot in advance.</p>

<p>Shani.</p>