title: Extract certain part from a string in R
body: <p>I would like to extract a part of the string. Here is an example dataset.</p>
  <pre><code>df &lt;- data.frame(id = c(1,2),
                   string = c('&lt;itemResponse&gt;&lt;response id=&quot;editIn_1.RESPONSE_1&quot;&gt;&lt;value&gt;ETC_CHOICE_2&lt;/value&gt;',
                              '&lt;itemResponse&gt;&lt;response id=&quot;editIn_1.RESPONSE_1&quot;&gt;&lt;value&gt;ETC_CHOICE_4&lt;/value&gt;'))
  
  &gt; df
    id                                                                       string
  1  1 &lt;itemResponse&gt;&lt;response id=&quot;editIn_1.RESPONSE_1&quot;&gt;&lt;value&gt;ETC_CHOICE_2&lt;/value&gt;
  2  2 &lt;itemResponse&gt;&lt;response id=&quot;editIn_1.RESPONSE_1&quot;&gt;&lt;value&gt;ETC_CHOICE_4&lt;/value&gt;
  </code></pre>
  <p>I would like to extract <code>ETC_CHOICE_2</code> and <code>ETC_CHOICE_4</code> from the long string. My desired output would be:</p>
  <pre><code>&gt; df
    id                                                                       string  extract
  1  1 &lt;itemResponse&gt;&lt;response id=&quot;editIn_1.RESPONSE_1&quot;&gt;&lt;value&gt;ETC_CHOICE_2&lt;/value&gt;  ETC_CHOICE_2
  2  2 &lt;itemResponse&gt;&lt;response id=&quot;editIn_1.RESPONSE_1&quot;&gt;&lt;value&gt;ETC_CHOICE_4&lt;/value&gt;  ETC_CHOICE_4
  </code></pre>
  <p>Does anyone have any idea?</p>
  <p>Thanks!</p>