Jump to content

text.replace()


scottybwoy

Recommended Posts

Why would text.replace give an error that it is not a function and halt the script?

 

Here is how it is evoked:

 

if (/^[\],:{}\s]*$/.test(text.replace(/\\./g, '@').
replace(/"[^"\\\n\r]*""|true|false|null|-?\d+(?:\.\d*)?(:?[eE][+\-]?\d+)?/g, ']').
replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {

}

 

Thanks

Link to comment
Share on other sites

sorry I can't help you their. I've only just started working with javascript last night.. so you probably know more than me :D

the syntax throws me off a bit. I keep doing silly things like:

toUpperCase(somevar);

instead of:

somevar.toUpperCase();

 

Which does throw up a non-function error. Maybe that's what's happening.. You're just setting it wrong sometimes.

Link to comment
Share on other sites

Why would text.replace give an error that it is not a function and halt the script?

 

Here is how it is evoked:

 

if (/^[\],:{}\s]*$/.test(text.replace(/\\./g, '@').replace(/"[^"\\\n\r]*""|true|false|null|-?\d+(?:\.\d*)?(:?[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {

}

 

Thanks

 

first im not sure if u can do replace like that, i dunno for a fact since i havent been coding js for long.

also try using var's instead of the long strings in the if.

 

this could be wrong, im just using what ive learned so far:P.

exp = '/^[\],:{}\s]*$/';
x = text.replace(/\\./g, '@');
x = x.replace(/"[^"\\\n\r]*""|true|false|null|-?\d+(?:\.\d*)?(:?[eE][+\-]?\d+)?/g, ']');
x = x.replace(/(?:^|:|,)(?:\s*\[)+/g, '');

if (exp.test(x)) {

}

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.