Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Location
    Now Southern Oregon. I was born and had lived my life in Los Angeles until relocating last year (2010)
    Posts
    211
    Thanks
    52
    Thanked 1 Time in 1 Post

    another RegExp mystery

    I have a situation where there is a string:
    m0|18:+:m1|(-3)
    which is a tracking method for preserving memory references
    in the following string:
    18+(-3)
    In the user interface of the project I am working on; the user
    changes the string to:
    (18+(-3))*8
    The object is to revise the memory tracking string to repersent
    the changes. should be: (m0|18+m1|(-3))*8
    Code:
    //matches = this.getMemVals()
    // getMemVals() searches the string 'm0|18:+:m1|(-3)' 
    // with regex pattern to find instances of m#|#
    var matches = new Array()
    matches[0] = 'm0|18';
    matches[1] = 'm1|(-3)';
    var currentStateSaved = '(18+(-3))*8';
    var glbs = '';
    for(i = 0; i < matches.length; i++)
       {
        var matRegex = new RegExp(matches[i].substring(matches[i].indexOf('|')+1), 'g');
        alert('matReg: '+matRegex);
        glbs = currentStateSaved.replace(matRegex, matches[i]);
       } 
    alert('GLBS: '+glbs) // <<< test code
    The '18' part of m0|18 is not be found in the revised literal string
    Why? (Has '18' been coverted to a number datatype?)

    This is the type of problem that drives me up a wall and cost far to
    much time trying to flush it out

    Thanks of suggestions, advice
    JK

  • #2
    Regular Coder
    Join Date
    Aug 2010
    Location
    Now Southern Oregon. I was born and had lived my life in Los Angeles until relocating last year (2010)
    Posts
    211
    Thanks
    52
    Thanked 1 Time in 1 Post

    Solved, without RegExp

    I solved the problem, albeit without the use of RegExp:

    Code:
    var glbs = '';
    var splits = currentStateSaved;
    for(i = 0; i < matches.length; i++)
       {
        var matSplit = new Array();
        matSplit = splits.split( matches[i].substring(matches[i].indexOf('|') +1) );
        splits = matSplit.join(matches[i]);
       }
    glbs = splits;
    alert('GLBS: '+glbs) // <<< test code
    In the process, I think I understand why the RegExp approach was not working.

    Thanks to anyone who looked, at least
    JK


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •