Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-06-2012, 10:27 PM   PM User | #1
anotherJEK
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: 152
Thanks: 41
Thanked 1 Time in 1 Post
anotherJEK is an unknown quantity at this point
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
anotherJEK is offline   Reply With Quote
Old 01-07-2012, 03:39 AM   PM User | #2
anotherJEK
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: 152
Thanks: 41
Thanked 1 Time in 1 Post
anotherJEK is an unknown quantity at this point
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
anotherJEK is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:12 PM.


Advertisement
Log in to turn off these ads.