string split with regex

Discussion in 'Javascript' started by Adrian Parker, Sep 28, 2005.

  1. 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
     
    Adrian Parker, Sep 28, 2005
    #1
    1. Advertising

  2. Adrian Parker

    ZER0 Guest

    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.
     
    ZER0, Sep 28, 2005
    #2
    1. Advertising

  3. "ZER0" <> wrote in message
    news:...
    > 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");
     
    Adrian Parker, Sep 28, 2005
    #3
  4. Ok, was being duh.. match splits it just fine.

    Thanks for the help.
     
    Adrian Parker, Sep 28, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Carlos Ribeiro
    Replies:
    11
    Views:
    704
    Alex Martelli
    Sep 17, 2004
  2. Replies:
    3
    Views:
    775
    Reedick, Andrew
    Jul 1, 2008
  3. Sam Kong
    Replies:
    5
    Views:
    247
    Rick DeNatale
    Aug 12, 2006
  4. Ruby Newbee

    regex =~ string or string =~ regex?

    Ruby Newbee, Jan 4, 2010, in forum: Ruby
    Replies:
    3
    Views:
    134
    Kirk Haines
    Jan 4, 2010
  5. Stanley Xu
    Replies:
    2
    Views:
    621
    Stanley Xu
    Mar 23, 2011
Loading...

Share This Page