title: Extract Base64 String
body: <p>I have a string from an <code>XML file</code> that I need to <code>base64</code> decode.
  However, it looks like there are some <em>invalid characters</em> within the string.</p>
  
  <p>I tried writing some code to remove any invalid characters, and then re-pad but it appears that my source data may have some invalid invisible characters within it.</p>
  
  <p>So, I figured the best approach since I know the valid base64 characters is to just have a function to extract all the valid characters, that way every invalid character would be purged. </p>
  
  <p><em>Is there an quick way to test this theory?</em></p>
  
  <p>My other question was about base64 itself,
  after researching it appears that while <code>A-Z,a-z,0-9</code> are <strong>62</strong> of the valid base64 characters the rest can depend on file encoding. </p>
  
  <p><em>Is it possible my file is using some other base64 scheme?</em></p>
  
  <p>When I scanned my file on top of the common <code>A-Z,a-z,0-9</code> I have found <code>=</code>'s within the files, not just as padding. I tried removing those and repadding, but I still seem to have invalid characters.</p>
  
  <p>This is now more a general question since I am unable to post my base64 encoded string.</p>
  
  <hr>
  
  <p><strong>Updated question</strong>
  This update is about the first part of my original question,</p>
  
  <p>If I have a string of say 1000 random character, and I want to remove every character that is not in a set. Say my set is "A","B",C","D",E","F","G". What would be the easiest (and fast, no loops) way to remove all characters which are not in the set?</p>