title: Replacing certain characters in email addresses with '*' in an SQL query
body: <p>I am trying to implement similar feature in my website and wanted to display email like below .</p>
  
  <p><img src="https://i.stack.imgur.com/BIWwp.png" alt="enter image description here"></p>
  
  <p>Below is the MYSQL code I have written and it is working OK for the scenarios I tested . But wanted to check with you guys if we have any better solution for this .</p>
  
  <pre><code>SELECT CONCAT(RPAD(CONCAT(RPAD(firstletter, firstpartlength - 2, '*'),
                     beforedomain), (
                              secondpartlength - Length(afterdot) +
                              firstpartlength ),
                       '*'), afterdot) hiddenemail
  FROM   (SELECT SUBSTRING(email, 1, 1)                             firstletter,
                 SUBSTRING(email, INSTR(email, '@') - 1, 3)         beforedomain,
                 SUBSTR(SUBSTRING(email, INSTR(email, '@')),
                 INSTR(SUBSTRING(email,
                       INSTR(email, '@')), '.'))
                        afterdot,
                 LENGTH(SUBSTRING(email, 1, INSTR(email, '@') - 1))
                 firstpartlength,
                 LENGTH(SUBSTRING(email, INSTR(email, '@') + 1))
                 secondpartlength
          FROM   test_table) a 
  </code></pre>
  
  <p>Thanks for your help</p>
  
  <p>Regards
  Kiran</p>