title: Like masked text, how to fill placeholders with text, and remove text to get back to placeholders?
body: <p>I would like to be able to merge two (maybe three) strings as shown below.  Is this possible using a regex?  (The base language I am using is Actionscript 3.0, but I can work with a more generic regex solution.)</p>
  
  <p>The idea is that <code>XYZ</code> (non-dash) chars are fixed in place, with the dashes getting replaced with the new chars, as needed.  Any additions are added as if a stack which skips around the fixed chars.  I imagine using a 3rd string: <code>---XYZ---</code> to maintain the placeholders.</p>
  
  <h2>Re to comments</h2>
  
  <p>Masked text input is what I am looking for, but adding from the right rather than the left.  The underscores represent placeholders for added chars.  They will actually be seen on screen (unless replaced, of course).</p>
  
  <p>An extensive example:</p>
  
  <p>Preparation: set the string length: <code>---------</code></p>
  
  <p>Preparation: set the fixed: <code>---XYZ---</code></p>
  
  <p>Add char: <code>---XYZ--a</code></p>
  
  <p>Add char: <code>---XYZ-ab</code></p>
  
  <p>Add char: <code>---XYZabc</code></p>
  
  <p>Add char: <code>--aXYZbcd</code></p>
  
  <p>Add char: <code>-abXYZcde</code></p>
  
  <p>Add char: <code>abcXYZdef</code></p>
  
  <p>Remove char: <code>-abXYZcde</code></p>
  
  <p>Remove char: <code>--aXYZbcd</code></p>
  
  <p>Remove char: <code>---XYZabc</code></p>
  
  <p>Add multiple chars: <code>abcXYZmno</code></p>
  
  <p>Remove multiple chars: <code>---XYZabc</code></p>
  
  <h2>ANSWER</h2>
  
  <p>Based on @Charmander's suggestion, here is a complete example:</p>
  
  <pre><code>var carr:Array = [];
  
  function fillMaskChars(maskText:String, chars:String, pop:Boolean = false):String
  {
      var maskLen:int = maskText.match(/-/g).length;
  
      if (pop)
      {
          carr.pop();
      }
      else if (carr.length &lt; maskLen)
      {
          carr = carr.concat(chars.split('', maskLen - carr.length));
      }
  
      if (carr.length == 0)
      {
          return maskText;
      }
  
      var i = carr.length - maskLen - 1;
  
      return maskText.replace(/-/g, function()
          {
              return carr[++i] || '-';
          });
  }
  </code></pre>
  
  <p>Some tests:</p>
  
  <pre><code>var characters:String = "oed";
  var curMask:String = "--W-RK---";
  
  var outText:String = maskChars(curMask, characters);
  trace(outText);
  
  characters = "!";
  outText = maskChars(curMask, characters);
  trace(outText);
  
  characters = "abcdefghij";
  outText = maskChars(curMask, characters);
  trace(outText);
  
  outText = maskChars(curMask, "", true);
  trace(outText);
  
  outText = maskChars(curMask, "", true);
  trace(outText);
  
  outText = maskChars(curMask, "", true);
  trace(outText);
  
  outText = maskChars(curMask, "", true);
  trace(outText);
  </code></pre>