title: Regex in R for capturing words spoken by a particular speaker from conversational text
body: <p>I am working with the following structured text.</p>
  <blockquote>
  <p>MR ARMSTRONG (in English): Hi Nice to meet you. PROF FLYNN (in English): I would like to talk about global warming today. MR ARMSTRONG (in English): I concur. There is no better time to talk about this. MRS CRUZ (in English): Good idea. Global warming is an alarming issue. MS PAMELA (in English): Absolutely. MR ARMSTRONG (in English): Absolutely agree. We should spend more time on discussing potential solutions. MS HENDERSON (in English): First of all, the international community should take action.</p>
  </blockquote>
  <p>I would like to extract the speech given by the respective participants by using regular expression. Say let’s focus on MR ARMSTRONG here.</p>
  <p>My desired output is as follows:</p>
  <blockquote>
  <p>MR ARMSTRONG (in English): Hi Nice to
  meet you.  MR ARMSTRONG (in English): I concur. There is no better
  time to talk about this.  MR ARMSTRONG (in English): Absolutely agree.
  We should spend more time on discussing potential solutions.</p>
  </blockquote>
  <p>What I can think of is the following: I know all the names of the participants in the conversation. As such, I can make use of regular expression with reference to the title and the ‘’(in English)’’.</p>
  <p>The code is as follows:</p>
  <pre><code>Armstrong &lt;- str_extract_all(sample_text,
  'MR ARMSTRONG \\(in\\s\\w+\\)\\:.*?(?=MRS\\s\\w+\\s\\(in\\s\\w+\\):)| MR ARMSTRONG \\(in\\s\\w+\\)\\:.*?(?=PROF\\s\\w+\\s\\(in\\s\\w+\\):)| MR ARMSTRONG \\(in\\s\\w+\\)\\:.*?(?=MS\\s\\w+\\s\\(in\\s\\w+\\):)')
  </code></pre>
  <p>But then there seem to be some problems with the OR logical operator ‘’|’’. If I put the MRS at front before PROF and MS (like the above pattern), then the output would include what PROF FLYNN said.</p>
  <blockquote>
  <p>OUTPUT: &quot;MR ARMSTRONG (in English): Hi Nice to meet you. PROF FLYNN
  (in English): I would like to talk about global warming today. MR
  ARMSTRONG (in English): I concur. There is no better time to talk
  about this. &quot;</p>
  </blockquote>
  <p>Another method I can think of is to capture the regular pattern of the capital letters before ‘(in English)’.</p>
  <pre><code>Armstrong_anothermethod &lt;- str_extract_all(sample_text,'MR ARMSTRONG \\(in\\s\\w+\\)\\:.*?(?=[A-Z]\\s\\(in\\s\\w+\\):)')
  </code></pre>
  <p>The output is as follows:</p>
  <blockquote>
  <p>[[1]]  [1] &quot;MR ARMSTRONG (in English): Hi Nice to meet you. PROF FLYN&quot;
  [2] &quot;MR ARMSTRONG (in English): I concur. There is no better time to
  talk about this. MRS CRU&quot;  [3] &quot;MR ARMSTRONG (in English): Absolutely
  agree. We should spend more time on discussing potential solutions. MS
  HENDERSO&quot;</p>
  </blockquote>
  <p>The problem is I do not know how to anticipate and hence get rid of the name of the next speaker after MR ARMSTRONG. It might be hard to do so as the names have irregular length. And the text only represents a small proportion of the entire text I have to deal with. Despite being capitalised and following the same pattern, there are many more names that are hard to be captured by regex like [A-Z]{1,10).</p>
  <p>Can someone please advise on the logical operator I should use or is there any way to match all the words in capital letters (e.g. PROF FLYNN) such that my second method can work better?</p>
  <p>Thanks so much</p>