string split with regex

A

Adrian Parker

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
 
A

Adrian Parker

ZER0 said:
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");
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top