...

View Full Version : regular expression or the split method?



Jerome
05-31-2005, 11:25 AM
Hi,

The reference-number of products is always product.number, f.e. suncream.1234

I would like to split every reference-number e.g. the part before the point and the part after.

What do you recommand to use? regular expressions or the split methode?

Thanks for Your time,
Jerome

jbot
05-31-2005, 11:36 AM
regular expressions or the split methode?

the latter should be sufficient:


alert("product:\t"+initialString.split(".")[0]);
alert("number:\t"+initialString.split(".")[1]);

:thumbsup:

Jerome
05-31-2005, 12:01 PM
Thanks for Your time and opinion!

martin_narg
05-31-2005, 01:05 PM
Of course if you wanted to use a regular expression, this would work nicely:



var str = "suncream.1234";
if( /([a-z_]*).([\d]*)/i.test(str) ) {
var strProductName = RegExp.$1;
var intProductNumber = RegExp.$2;
}


however, it is much of a muchness and jbot has already answered your question, i just like regular expressions ;)

m_n

jbot
05-31-2005, 01:34 PM
i just like regular expressions

they certainly have their place, just as nutcrackers and sledgehammers have their's too. just use them wisely, and appropriately.

martin_narg
05-31-2005, 01:45 PM
very true indeed mate ;)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum