View Full Version : split()/Regex/IE
syktek
02-17-2009, 02:35 AM
i'm not sure how many people have actually know about this issue but IE seems to drop empty values on split() when using a regex but retains the empty values when using a string.
var field = "this~~is~~testing~~split()";
var valsRegex = field.split(/~/);
var valsStrng = field.split('~');
document.write('<p>this is using a regex to find ~<br />' + valsRegex + ' <!--[if IE]><span style="color:red;"><-- look, IE drops empty values</span><![endif]--></p>');
document.write('<p>this is using a string to find ~<br />' + valsStrng + '</p>');
i've learned to use regex sparingly after this, figure i would share.
oesxyl
02-17-2009, 02:40 AM
i'm not sure how many people have actually know about this issue but IE seems to drop empty values on split() when using a regex but retains the empty values when using a string.
var field = "this~~is~~testing~~split()";
var valsRegex = field.split(/~/);
var valsStrng = field.split('~');
document.write('<p>this is using a regex to find ~<br />' + valsRegex + ' <!--[if IE]><span style="color:red;"><-- look, IE drops empty values</span><![endif]--></p>');
document.write('<p>this is using a string to find ~<br />' + valsStrng + '</p>');
i've learned to use regex sparingly after this, figure i would share.
this belong to javascript forum not "post a javascript". please, don't post again, ask one of the moderators to move the thread.
regards
syktek
02-17-2009, 02:02 PM
this belong to javascript forum not "post a javascript". please, don't post again, ask one of the moderators to move the thread.
regards
mods, feel free to delete. obviously sharing my script does not fall under post a script.
oesxyl
02-17-2009, 02:15 PM
i'm AM posting a javascript, a script example of an error cause under certain conditions. what is "post a javascript" meant for if not to share a script written? i'm not asking questions or for help but sharing a script and information about it.
if it needs to be moved then i guess move it.
My apologize, :)
too many people post problems without a question waiting for an answer in this forum and "error" make me think to that case.
It's probably a good idea to give more details about your script to avoid future confusion like this.
best regards
vBulletin® v3.8.2, Copyright ©2000-2010, Jelsoft Enterprises Ltd.