Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Come to my aid, all ye regex wizards!

Options
  • 19-08-2001 10:41pm
    #1
    Registered Users Posts: 1,842 ✭✭✭


    Right, well I'm no good at these, so I'm wondering if any of you can give me a hand here.

    What I need is a regex or something which will find all orrurances of ' href="blahblahblah" ' and, if the 'blahblahblah' part does not begin with 'http://' I want it to add a string to the beginning, and append the existing "href" parameter.

    I probably haven't explained this well enough, here's a few examples.

    $myaddy = "http://www.me.com/script?url=";
    $theiraddy = "http://www.them.com/";

    <a href="about.php">about</a>
    If the above line was input, it would change to:
    <a href="http://www.me.com/script?url=http://www.them.com/about.php">about</a&gt;

    Is that clear enough?

    Basically I'm getting a script of mine to grab a site, re-write all the relative links, image tags, etc, so the page served by my site will work properly, links, images/etc.

    Oh it does some translating on the text in it too but I have that sorted. smile.gif


Comments

  • Registered Users Posts: 654 ✭✭✭DS


    Well I'm only familiar with JavaScript's RegExp object, but you can probably adapt it w/o too much hassle.
    Here's how I'd match href="...":
    /href="(.+)"/gi
    The dot for any character, the plus for one or more times, the g for global match and i for case insensitivity.
    Then presuming you need to change what's inside the quotes, reference the group (in brackets) with \1, $1 or however you do it.
    Sorry for the incredibly high levels of vagueness :P, it's hard when I don't speak your language, as it were. You'll probably do better with the next reply...

    Gamers Europe :: Keeping It Simple


Advertisement