title: matlab most efficient partial string subtract/regex
body: <p>I have a project where I have a huge list of email addresses (i.e. johnhahifas@example.com) and I have a list of top 5000 most common First names (i.e. john, jim etc)</p>
  
  <p>I am trying to for each email address, remove any First name if it appears in the email, so that for example:</p>
  
  <p>johnhahifas@example.com becomes hahifas@example.com </p>
  
  <p>benTTTben@something.com becomes TTT@something.com</p>
  
  <p>so far, I came up with a regex solution and a strfind solution, the regexprep is much faster; I even optimized it a little to remove the @example.com so that the operation might be faster; but it still takes forever to run.</p>
  
  <p>you can download the common first names from this address (CSV file)
  <a href="http://www.quietaffiliate.com/Files/CSV_Database_of_First_Names.csv" rel="nofollow">http://www.quietaffiliate.com/Files/CSV_Database_of_First_Names.csv</a></p>
  
  <p>The regex code I have:</p>
  
  <pre><code>fileID = fopen('bademails');  
  emails = textscan(fileID,'%s');
  str = emails{1,1}; %//Loaded in the emails
  
  fileID = fopen('CSV_Database_of_First_Names.csv');  
  names = textscan(fileID,'%s');
  Names = lower(names{1,1}); %//Loaded in the Names
  
  K = regexprep(str,Names,''); %Regex on Names
  </code></pre>
  
  <p>Any faster solutions would be much appreciated, thank you in advance!</p>