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
https://forums.phpfreaks.com/topic/78079-textreplace/
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
https://forums.phpfreaks.com/topic/78079-textreplace/#findComment-395896
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
https://forums.phpfreaks.com/topic/78079-textreplace/#findComment-398263
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.