www.webdeveloper.com
Results 1 to 3 of 3

Thread: split not recognising return from regex as string?

  1. #1
    Join Date
    Sep 2011
    Posts
    2

    split not recognising return from regex as string?

    Hello all,

    I'm working on a function that checks the css href in an included html file and if it is incorrect it adjusts it. my problem is in this piece of code
    Code:
    hrefrege = /href=\"[^ ]+\"/i;
    originalHref = m[0].match(hrefrege);
    originalHrefArray = originalHref.split("/");
    alert(originalHrefArray[0]);
    Now the m[0] variable is set before this piece of code, containing
    Code:
    <LINK HREF="css/style_oud.css" REL="stylesheet" TYPE="text/css">
    the originalHref matches the href="css/style_oud.css" however the split function doesn't recognise originalHref as a string.

    Why doesn't it recognise it and how do i fix my problem?

    Thanks in advance,

    Keldaros

  2. #2
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,276
    This script show that originalHref is an object. Than you have to build a string.
    HTML Code:
    var hrefrege = /href=\"[^ ]+\"/i;
    var m='<LINK HREF="css/style_oud.css" REL="stylesheet" TYPE="text/css">';
    var originalHref = m.match(hrefrege);alert(typeof(originalHref))
    var originalHrefArray = originalHref.toString().split(/\//g);
    alert(originalHrefArray);
    Split works better with all browsers with a regexp and a the option g...

  3. #3
    Join Date
    Sep 2011
    Posts
    2
    Hi 007Julien,

    Thanks alot, that did the trick!

    Keldaros

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles