Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8226953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:57:15+00:00 2026-06-07T15:57:15+00:00

I would like to be able to merge two (maybe three) strings as shown

  • 0

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.)

The idea is that XYZ (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: ---XYZ--- to maintain the placeholders.

Re to comments

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).

An extensive example:

Preparation: set the string length: ---------

Preparation: set the fixed: ---XYZ---

Add char: ---XYZ--a

Add char: ---XYZ-ab

Add char: ---XYZabc

Add char: --aXYZbcd

Add char: -abXYZcde

Add char: abcXYZdef

Remove char: -abXYZcde

Remove char: --aXYZbcd

Remove char: ---XYZabc

Add multiple chars: abcXYZmno

Remove multiple chars: ---XYZabc

ANSWER

Based on @Charmander’s suggestion, here is a complete example:

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 < 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] || '-';
        });
}

Some tests:

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);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T15:57:17+00:00Added an answer on June 7, 2026 at 3:57 pm

    I think you will find an array more appropriate. I’m afraid I have no experience in ActionScript, but it should not be difficult to translate from JavaScript.

    function fillMaskWithCharacters(mask, characters) {
        var masked = mask.match(/-/g).length;
        var i = 0;
    
        return mask.replace(/-/g, function() {
            return characters[--i + masked] || '-';
        });
    }
    

    It is passed an array of characters, which you may manipulate as necessary. For example:

    fillMaskWithCharacters('--w-rk---', ['!', 'd', 'e', 'o']); // "--worked!"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to be able to merge two files into one during configure
I would like to merge two arrays containing a list of files plus their
I would like to be able to fusion an IEnumerable<IEnumerable<T>> into IEnumerable<T> (i.e. merge
I would like to be able to keep two separate branches in a git
Would like to be able to set colors of headings and such, different font
I would like to be able to output the name of a variable, along
I would like to be able to print in the logs a message for
I would like to be able to show a personal message to abusers of
I would like to be able to create a variable that holds an instance
I would like to be able to go: sed s/^\(\w+\)$/leftside\1rightside/ and have the group

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.