Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > string split with regex

Reply
Thread Tools

string split with regex

 
 
Adrian Parker
Guest
Posts: n/a
 
      09-28-2005
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







 
Reply With Quote
 
 
 
 
ZER0
Guest
Posts: n/a
 
      09-28-2005
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.

 
Reply With Quote
 
 
 
 
Adrian Parker
Guest
Posts: n/a
 
      09-28-2005

"ZER0" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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");



 
Reply With Quote
 
Adrian Parker
Guest
Posts: n/a
 
      09-28-2005
Ok, was being duh.. match splits it just fine.

Thanks for the help.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use String.split to split a mixed encoding string(partencoded in gbk, part encoded in utf-8) Stanley Xu Ruby 2 03-23-2011 02:06 PM
regex =~ string or string =~ regex? Ruby Newbee Ruby 3 01-04-2010 06:04 PM
How make regex that means "contains regex#1 but NOT regex#2" ?? seberino@spawar.navy.mil Python 3 07-01-2008 03:06 PM
String#split(/\s+/) vs. String#split(/(\s+)/) Sam Kong Ruby 5 08-12-2006 07:59 PM
Small inconsistency between string.split and "".split Carlos Ribeiro Python 11 09-17-2004 05:57 PM



Advertisments