title: R, Regex, and Matching the Choice of a Qualtrics Response Column
body: <p>When you export response data from Qualtrics as a CSV, the 2nd row of the data contains strings with the question stem (shortened if necessary), followed by a dash, followed by that response column's corresponding choice. As an example, if my question were "Please select all of the fruit you enjoy:", in my response data the second row of a response column to this question might contain something like "Please select all of the fruit you enjoy:-Blueberries". </p>
  
  <p>Qualtrics shortens the question stem if it is longer than 100 characters. If it is more than 100 characters, the stem is cut off after the 99th character, "..." is appended, and then the dash, and then the choice text. </p>
  
  <p>I am trying to retrieve the text that is after this dash. However, that's difficult, because both the choice text and the question text could contain dashes. I have thought of two different approaches I could take in attempting to select just the choice text:</p>
  
  <ol>
  <li><p>I have the question text, and can reliably programmatically retrieve it based on the response column name. However, the question text doesn't always match exactly, because Qualtrics removes any HTML styling in the Question text in the response data, but not in the Qualtrics survey file that I am getting the question text from. For questions that don't have any HTML styling, I was thinking about trying to use the question text to somehow match up to and including the dash between the question text and the choice text. I think regex could handle this case fine, but this clearly doesn't work without heavy modification for any questions that have HTML components.</p></li>
  <li><p>The alternative I think might be more reliable. Strip the question text from the QSF file of any HTML tags, and then count how many "-" characters appear in the question text. Call that <code>n</code>, and then match the 2nd-row-response-entry for up to the <code>n+1</code>th dash, remove it, and what's remaining is my choice text. </p></li>
  </ol>
  
  <p>I think the 2nd option is much more likely to work consistently, since the first option leaves me with a case where I have to try and strip html from the question text in exactly the same way Qualtrics does, unless I use fuzzy matching (which I know nothing about). However, the second option is also unclear to me. </p>
  
  <p><a href="http://www.sharecsv.com/s/fa32c0fcebb5759f1a3902589054fb54/Multiple_Answer_MC_Questions.csv" rel="nofollow">an example csv response set</a></p>
  
  <p>For example, the first question's question text looks like this in the QSF:</p>
  
  <pre><code>"&lt;div style=\"text-align: center;\"&gt;Click to write the question text
  &lt;span style=\"font-size: 10.8333px;\"&gt;thsi&lt;sup&gt;tasdf&lt;em&gt;werasfd&lt;/em&gt;&lt;/sup&gt;
  &lt;em&gt;sdfad&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;\n&amp;nbsp;&lt;/div&gt;"
  </code></pre>
  
  <p>I would appreciate both of the following: advice on which option (or a suggestion for another) you think has the most chance for success, and help with the regex in R for matching the text up to the <code>n+1</code>th "-" character. </p>