preg_match type split

Discussion in 'Javascript' started by Captain Paralytic, Mar 5, 2007.

  1. I have the following string in a variable:

    '\074a href="" onClick="pl_go(64);return false;">James T Kirk\074/
    a>',
    '\074a href="" onClick="pl_go(64);return false;">thecaptain\074/a>',
    '\074a href="" onClick="pl_go(64);return
    false;">\074/a>'


    (there are 3 newlines in there).
    Is there a simple (possibly regex?) way to split this out to an array
    to end
    up like:


    elem[0] = 64
    elem[1] = 'James T Kirk'
    elem[2] = 'thecaptain'
    elem[3]= ''


    TIA
    Captain Paralytic, Mar 5, 2007
    #1
    1. Advertising

  2. Captain Paralytic

    Evertjan. Guest

    Captain Paralytic wrote on 05 mrt 2007 in comp.lang.javascript:

    > I have the following string in a variable:
    >
    > '\074a href="" onClick="pl_go(64);return false;">James T Kirk\074/
    >a>',
    > '\074a href="" onClick="pl_go(64);return false;">thecaptain\074/a>',
    > '\074a href="" onClick="pl_go(64);return
    > false;">\074/a>'
    >
    >
    > (there are 3 newlines in there).
    > Is there a simple (possibly regex?) way to split this out to an array
    > to end
    > up like:
    >
    >
    > elem[0] = 64
    > elem[1] = 'James T Kirk'
    > elem[2] = 'thecaptain'
    > elem[3]= ''


    Yes, there is.

    What javascript did you try yet?

    Is this a [school] assignment?


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Mar 5, 2007
    #2
    1. Advertising

  3. Captain Paralytic

    Evertjan. Guest

    Evertjan. wrote on 05 mrt 2007 in comp.lang.javascript:

    > Captain Paralytic wrote on 05 mrt 2007 in comp.lang.javascript:
    >
    >> I have the following string in a variable:
    >>
    >> '\074a href="" onClick="pl_go(64);return false;">James T Kirk\074/
    >>a>',
    >> '\074a href="" onClick="pl_go(64);return false;">thecaptain\074/a>',
    >> '\074a href="" onClick="pl_go(64);return
    >> false;">\074/a>'
    >>
    >>
    >> (there are 3 newlines in there).
    >> Is there a simple (possibly regex?) way to split this out to an array
    >> to end
    >> up like:
    >>
    >>
    >> elem[0] = 64
    >> elem[1] = 'James T Kirk'
    >> elem[2] = 'thecaptain'
    >> elem[3]= ''

    >
    > Yes, there is.
    >
    > What javascript did you try yet?
    >
    > Is this a [school] assignment?
    >
    >


    <script type='text/javascript'>

    var elem = [];
    var s =
    "'\\074a href=\"\" onClick=\"pl_go(64);"+
    "return false;\">James T Kirk\\074/a>/n',"+
    "'\\074a href=\"\" onClick=\"pl_go(64);"+
    "return false;\">thecaptain\\074/a>/n',"+
    "'\\074a href=\"\" onClick=\"pl_go(64);"+
    "return false;\">\\074/a>/n'";


    elem[0] = s.match(/pl_go\([^\)]*/)[0].replace(/pl_go\(/,'');

    r = s.match(/">([^\\]*)/g);
    for (var i=0;i<r.length;i++)
    elem[i+1] = r.replace(/">/,'');

    for (i=0;i<elem.length;i++)
    document.write("elem["+i+"] = "+elem+"<br>");

    </script>

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Mar 5, 2007
    #3
  4. On 5 Mar, 12:17, "Evertjan." <> wrote:
    > Captain Paralytic wrote on 05 mrt 2007 in comp.lang.javascript:
    >
    >
    >
    >
    >
    > > I have the following string in a variable:

    >
    > > '\074a href="" onClick="pl_go(64);return false;">James T Kirk\074/
    > >a>',
    > > '\074a href="" onClick="pl_go(64);return false;">thecaptain\074/a>',
    > > '\074a href="" onClick="pl_go(64);return
    > > false;">\074/a>'

    >
    > > (there are 3 newlines in there).
    > > Is there a simple (possibly regex?) way to split this out to an array
    > > to end
    > > up like:

    >
    > > elem[0] = 64
    > > elem[1] = 'James T Kirk'
    > > elem[2] = 'thecaptain'
    > > elem[3]= ''

    >
    > Yes, there is.
    >
    > What javascript did you try yet?
    >
    > Is this a [school] assignment?
    >
    > --
    > Evertjan.
    > The Netherlands.
    > (Please change the x'es to dots in my emailaddress)- Hide quoted text -
    >
    > - Show quoted text -


    It's not a school assignment, just a guy who knows php better than JS.

    I was hoping there'd be a slick way to parse this.
    Captain Paralytic, Mar 5, 2007
    #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. Replies:
    2
    Views:
    465
  2. Carlos Ribeiro
    Replies:
    11
    Views:
    695
    Alex Martelli
    Sep 17, 2004
  3. trans.  (T. Onoma)

    split on '' (and another for split -1)

    trans. (T. Onoma), Dec 27, 2004, in forum: Ruby
    Replies:
    10
    Views:
    209
    Florian Gross
    Dec 28, 2004
  4. Sam Kong
    Replies:
    5
    Views:
    236
    Rick DeNatale
    Aug 12, 2006
  5. Paul Lautman

    preg_match type split

    Paul Lautman, Mar 4, 2007, in forum: Javascript
    Replies:
    0
    Views:
    86
    Paul Lautman
    Mar 4, 2007
Loading...

Share This Page