title: Remove all text from string after a sequence of words in Scala
body: <p>I am trying to assemble a UDF in Scala that takes a column from a data frame and manipulates it to remove HTML and other useless pieces of text.</p>
  
  <p>The column I need to modify is very messy, sometimes there is HTML, sometimes there is not... Searching SO I have found a regex solution to <a href="https://stackoverflow.com/questions/7769454/scala-strip-all-html-tags-from-string-except-links">remove HTML</a></p>
  
  <p>what I'd like to accomplish now is to find a regex that can find a specific word in the text and delete all the text after that word. </p>
  
  <p>I think I understand from <a href="https://stackoverflow.com/questions/22689439/remove-all-after-this-char-or-a-specific-word-with-regex">this SO answer</a> that the regex should be something like <code>\).*</code> if you want to remove all after <code>)</code>, so I am trying to adapt this to my case, unsuccessfully due to my lack of knowledge about regex.</p>
  
  <p>I have strings like:</p>
  
  <pre><code>I am interested to hear from you, thanks   Sent from iPhone   other stuff I want to delete....
  </code></pre>
  
  <p>I'd like to retain the first part of the string up to "Sent from" excluded, so a perfect output would be:</p>
  
  <pre><code>I am interested to hear from you, thanks
  </code></pre>
  
  <p>What I have so far is something like:</p>
  
  <pre><code> val toStringNoHTML = udf[String, String](_.toString
      // code from SO as linked above
      .replaceAll("""&lt;(?!\/?a(?=&gt;|\s.*&gt;))\/?.*?&gt;""", " ")
      // delete all text after key word
      .replaceAll("""'Sent from'.*""", "")
      // remove all punctuation
      .replaceAll("""[\p{Punct}\n]""", " ")
      )
  </code></pre>
  
  <p>While the HTML gets remove, the "Sent from" and all the text after does not. Any hint how to adjust the regex to make it work?</p>
  
  <p><strong>EDIT</strong>
  as pointed out in the comment, a small typo prevented my code to work, thanks for the help:</p>
  
  <pre><code>.replaceAll("""'Sent from'.*""", "")
  </code></pre>
  
  <p>should be</p>
  
  <pre><code>.replaceAll("""Sent from.*""", "")
  </code></pre>