469,914 Members | 2,389 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,914 developers. It's quick & easy.

string split with regex

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
3 1440
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

"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
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.

Similar topics

5 posts views Thread by Blue Ocean | last post: by
1 post views Thread by Guadala Harry | last post: by
6 posts views Thread by Bruce Wiebe | last post: by
3 posts views Thread by Michael D Murphy | last post: by
28 posts views Thread by Materialised | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.