title: Extract Emails that Lying Between Special Characters Using Regex in SQL
body: <p>How do I extract only email from this certain pattern of string using regex in SQL?</p>
  <p><strong>What I have :</strong>
  tb_1</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Logmessage</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>Alan Robert &lt;alan.robert@gmail.com&gt; was assigned to &lt;richard@yahoo.com&gt; and &lt;nelson@gmail.com&gt;</td>
  </tr>
  <tr>
  <td>Alan Robert &lt;alan.robert@gmail.com&gt; was unassigned to &lt;khanjoyty@gmail.com&gt; and &lt;katy@gmail.com&gt;</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p><strong>What I want:</strong> tb_2</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>email_1</th>
  <th>email_2</th>
  <th>email_3</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>alan.robert@gmail.com</td>
  <td>richard@yahoo.com</td>
  <td>nelson@gmail.com</td>
  </tr>
  <tr>
  <td>alan.robert@gmail.com</td>
  <td>khanjoyty@gmail.com</td>
  <td>katy@gmail.com</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I already have a solution for this but the tb_1 table has a huge amount of rows so my query output takes too much time. That's why I thought maybe <strong>regex</strong> would be more time-saving.</p>
  <p><strong>My query:</strong></p>
  <pre><code>with cte as(
  Select replace(replace(replace(replace(right(@logmessage, len(logmessage)-charindex('&lt;', logmessage)+1), 
                                           Case when logmessage like '%unassigned%' Then ' was unassigned to ' 
                                         When logmessage like '%assigned%' then ' was assigned to ' End , '.'),' and ', '.'), 
                                                                          '&lt;', '['  ),'&gt;', ']') logmessage
  From tb_1)
  
  Select 
         PARSENAME(logmessage, 3) AS email_3,
         PARSENAME(logmessage, 3) AS email_2,
         PARSENAME(logmessage, 1) AS email_1
  From cte
  </code></pre>