#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    73
    Rep Power
    15
    I know we have to use reg. expression, but any suggestions would be very helpful!
    for example: <a href="link.htm"> --> <a href="http://domain.com/link.htm">

    (that is just a SIMPLE form of link, take other formats of hyperlink into consideration too)



    ------------------
    http://new.123finder.com/ - Helps you find cool domains for FREE & Registers it for only $14.95/yr
    http://www.guideclick.com/ - Qualified webmaster resources (affiliate programs, web design, tips)

    ------
    Son
  2. #2
  3. No Profile Picture
    RyanP
    Guest
    Devshed Newbie (0 - 499 posts)
    this should work, assuming that the double quote of the a href is the first double quote in the string
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>$var = "<a href="link.html">";
    $domain = "http://domain.com/";


    $var =~ s/"/"$domain/;
    // $var is now
    // <a href="http://domain.com/link.html">[/code]


    [This message has been edited by RyanP (edited August 22, 2000).]
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    81
    Rep Power
    15
    You can also collapse out any ..'s in your path using:
    $var =~ s![^/]*/../!!g;
    Just makes it look prettier. :-)
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    FL
    Posts
    5
    Rep Power
    0
    this hack would work:

    $domain = "http://www.yourdomain.com/";

    s/a href="/a href="$domain/;
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    73
    Rep Power
    15
    I gonna try these solutions now! Thanks guys
    For the last solution, "<A" need not go together with "HREF", so if you use it, in most cases, it's okay, but the error is there!!

    ------------------
    http://new.123finder.com/ - Helps you find cool domains for FREE & Registers it for only $14.95/yr
    http://www.guideclick.com/ - Qualified webmaster resources (affiliate programs, web design, tips)

    ------
    Son
  10. #6
  11. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    >>this hack would work:
    >>$domain = "http://www.yourdomain.com/";
    >>s/a href="/a href="$domain/;

    This would fail in many ways:

    1) <A href="link.htm">
    2) <a HREF="link.htm">
    3) <a href ="link.htm">
    4) <a href= "link.htm">

    Always expect what worse things can happen. All four above are valid hyperlinks. Even the URL without quotes.

    Check this out -> http://www.devshed.com/Talk/Forums/F...ML/001858.html

    [This message has been edited by freebsd (edited August 23, 2000).]
  12. #7
  13. No Profile Picture
    RyanP
    Guest
    Devshed Newbie (0 - 499 posts)
    chris: what are those bangs in your RE for? i've never seen them used like that
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    81
    Rep Power
    15
    Ah, this is the rather tasty feature of Perl that allows you to choose your quote characters. There's no rule that says you have to use / to delimit your regular expressions (or that you have to use " to delimit an interpolated string, or ' to delimit a non-interpolated string, for that matter). You can specify your quote character as you need. So you can do:
    s!find!replace!g
    or even
    s(find){replace}g
    (Perl will allow you to use naturally paired delimiters).
    For quotes, you can do:
    q/my string/
    for a non-interpolated string, and
    qq/my string/
    for an interpolated string
    You don't have to use / there, you can use any non-alphanumeric, non-whitespace character.

    There is a shortcut regarding /'s whereby
    $var =~ /regexp/
    is interpreted as
    $var =~ m/regexp/

    Check out the perlop manpage for more info:
    perldoc perlop

IMN logo majestic logo threadwatch logo seochat tools logo