By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,814 Members | 2,162 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,814 IT Pros & Developers. It's quick & easy.

string split with regex

P: n/a
I have a string I have to parse

AB1.2CD34

I need to split the string into groups of letters and numbers..

"AB" "1.2" "CD" "34"

What is the best way of doing this ?

I've looked at string.split using a regex, but that doesn't output the
delimiters.

Thanks
Adrian



Sep 28 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Wed, 28 Sep 2005 14:27:10 GMT, Adrian Parker wrote:
I have a string I have to parse
AB1.2CD34 I need to split the string into groups of letters and numbers..
"AB" "1.2" "CD" "34"


var str="AB1.2CD34";
alert(str.match(/[0-9\.]+|[A-Za-z]+/g));

--
~ Tenete la morte lontano dalle strade. Guidate sul marciapiede.

Sep 28 '05 #2

P: n/a

"ZER0" <ze********@libero.it> wrote in message
news:c6**************@ID-171124.news.individual.net...
var str="AB1.2CD34";
alert(str.match(/[0-9\.]+|[A-Za-z]+/g));


What am I missing, the following returns a zero length array.

function splitit(str) {
var splitz = str.split(/[0-9\.]+|[A-Za-z]+/g);
alert(splitz.length);
}

splitit("B1.2CD34");

Sep 28 '05 #3

P: n/a
Ok, was being duh.. match splits it just fine.

Thanks for the help.
Sep 28 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.