Help with a Javascript/Regex issue

Hello, I am trying to take a string and manipulate some of the characters using Regex Ecmascript version.  Here is the scenario:

String is called "Hello World gr8tly".  

1.  Capture the first and last characters of each string.  Result:  Ho, Wd, gy
2.  Capture the remaining characters from each.  result: ell, orl, r8tl
3.  Capture distinct.  result:  el, orl, r8tl
4.  Count distinct.  result: 2, 3, 4
5.  Join steps 1 and 4 together.  result:  H2o, W3d, g48tl.  White space should not be counted.  Need to allow for special characters

Here is my current code:
    <form id="form1" runat="server">
        <asp:Label ID="Label1" runat="server" Text="Enter word or phrase in this box:"></asp:Label><br />
        <textarea id="one" runat= "server" style="overflow:hidden; width:500px; height:100px"></textarea><br />
        <asp:Label ID="Label2" runat="server" Text="Here Is detailed string breakdown:"></asp:Label><br />
       <textarea id="two" runat="server" style="overflow:hidden; width:500px; height:100px"></textarea><br />
<asp:Label ID="Label3" runat="server" Text="This shows the speacial 3 character code: "></asp:Label><br />
<textarea id="three" runat="server" style="overflow:hidden; width:500px; height:100px"></textarea><br />
        <asp:Label ID="Label4" runat="server" Text="This shows the speacial 3 character code: "></asp:Label><br />
<textarea id="four" runat="server" style="overflow:hidden; width:500px; height:100px"></textarea><br />
        <input id="Reset1" type="reset" value="reset" />
<script src="" type="text/javascript"></script>


    $('#one').keyup(function (e) {
        var txtVal = $(this).val();

I appreciate your help with this.  Please let me know if you need more details.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dan CraciunIT ConsultantCommented:
Is this homework?

Anyway, this is not a regex problem, it's a substring problem.
Blessed7777Author Commented:
What is the solution?  No this is not homework, I am trying to learn regex on my own time.  I this something you can assist with?
Blessed7777Author Commented:
I tried concatenating the results from each line. The individual lines are working correctly showing str1=H,W,g

in stead of Ho,Wd,gy I get H,W,g,o,d,y.  How does var newString = str1.concat(str2); need to be in order to get the correct order?

Here is my code:

$('#one').keyup(function (e) {
                var txtVal = $(this).val();
                var str1 = (txtVal.match(/\b(\w)/g));
                var str2 = (txtVal.match(/(\w)\b/g));
                var newString = str1.concat(str2);
The function below will return an array with the items you want.
var str="Hello World gr8tly";

var result = parse_it(str);

alert( result ); 

function parse_it(str)
    var matches = null;
    var rule_1=[];
    var rule_2=[];
    var result=[];
    while( (matches = str.match( /\b([a-z])([a-z0-9]*?)([a-z0-9])\b/i) ) )
        str = str.replace(matches[0],'');
    for( var i=0;i<rule_2.length; ++i)
        var str = rule_2[i];
        for(var j=0; j<str.length; ++j)
            var l = str.charAt(j);
            str = str.substr(0,j+1)+str.substring(j+1).replace(l,'')
        rule_2[i] = str;
        result[result.length] = rule_1[i].charAt(0) + str.length + rule_1[i].charAt(1);
    return result;

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Blessed7777Author Commented:
Thank you for your help with his hielo.  I am new to regex so I have a little bit of a learning curve.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Regular Expressions

From novice to tech pro — start learning today.