Ask a Question related to PERL Miscellaneous, Design and Development.

  1. #1

    Default Matching URls

    Hi,

    Does anyone know of a link to or an example of a decent regexp that wil
    recognize internet URLs? (It needs to match urls starting with http:// and
    [url]www.)[/url]

    I am trying to replace a string like
    "My Homepage is @ http://www.homepage.nl"
    with
    "My Homepage is @ <A HREF =
    'http://www.homepage.nl'>http://www.homepage.nl</A>"

    Thx, Seansan


    Seansan Guest

  2. Similar Questions and Discussions

    1. can you please checkout these urls
      Can you please checkout these URLs http://images.optin.com.au/optusxmas/flash/penguin_tebe.swf?msg=satish http://www.diesel.com/ When we observe...
    2. iframe URLS
      Hi, I was wondering whether it was possible to define a URL which links to a page containing and iframe and define which src to display in the...
    3. dynamic URLS convert to static URLS for search engines
      We use ASP.net and all our pages are dynamically created and search engines such as Google does not like dynamically created pages to index. What is...
    4. Different urls to same ws?
      Hi! We are developing a web service that needs to use several databases (each company that uses this web service has their own database). Is it...
    5. Send me you URLs
      "Give me your tired, your poor, Your huddled masses yearning to breathe free, The wretched refuse of your teeming shore. Send these, the homeless,...
  3. #2

    Default Re: Matching URls

    Seansan wrote:
    > Does anyone know of a link to or an example of a decent regexp that wil
    > recognize internet URLs? (It needs to match urls starting with http:// and
    > [url]www.)[/url]
    perldoc URI::Find
    and
    perldoc URI::Find::Schemeless

    hth, tina
    --
    [url]http://www.tinita.de/[/url] \ enter__| |__the___ _ _ ___
    [url]http://Movies.tinita.de/[/url] \ / _` / _ \/ _ \ '_(_-< of
    [url]http://www.perlquotes.de/[/url] \ \ _,_\ __/\ __/_| /__/ perception
    - my mail address expires end of august 2003 -
    Tina Mueller Guest

  4. #3

    Default Re: Matching URls

    On 20 Jul 2003, Tina Mueller wrote:
    >Seansan wrote:
    >
    >> Does anyone know of a link to or an example of a decent regexp that wil
    >> recognize internet URLs? (It needs to match urls starting with http:// and
    >> [url]www.)[/url]
    >
    >perldoc URI::Find
    >and
    >perldoc URI::Find::Schemeless
    Damn those URIs and their zany schemes.

    --
    Jeff Pinyan RPI Acacia Brother #734 2003 Rush Chairman
    "And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
    years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
    Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)

    Jeff 'japhy' Pinyan Guest

  5. #4

    Default Re: Matching URls

    "Seansan" <sheukels=cuthere=@yahoo.co.uk> wrote in message news:<3f1aa893$0$61643$e4fe514c@dreader3.news.xs4a ll.nl>...
    > Hi,
    >
    > Does anyone know of a link to or an example of a decent regexp that wil
    > recognize internet URLs? (It needs to match urls starting with http:// and
    > [url]www.)[/url]
    >
    > I am trying to replace a string like
    > "My Homepage is @ http://www.homepage.nl"
    > with
    > "My Homepage is @ <A HREF =
    > 'http://www.homepage.nl'>http://www.homepage.nl</A>"
    >
    > Thx, Seansan
    ## I think this is what you want. Good luck.
    ## JR

    #!/perl
    use strict;
    use diagnostics;
    use warnings;

    while(<DATA>) {
    s/(http:\/\/www.*)\b/<a href='$1'>$1<\/a>/g;
    print $_, "\n";
    }

    __DATA__
    My homepage is @ [url]http://www.homepage.nl[/url]
    My favorite site is @ [url]http://www.espn.com[/url]
    My second most favorite site is @ [url]http://www.whatever.org[/url]

    =pod
    ## OUTPUT

    My homepage is @ <a href='http://www.homepage.nl'>http://www.homepage.nl</a>
    My favorite site is @ <a
    href='http://www.espn.com'>http://www.espn.com</a>
    My second most favorite site is @ <a
    href='http://www.whatever.org'>http://www.whatever.org</a>

    =cut
    JR Guest

  6. #5

    Default Re: Matching URls

    Seansan wrote:

    ....

    > Does anyone know of a link to or an example of a decent regexp that wil
    > recognize internet URLs? (It needs to match urls starting with http:// and
    > [url]www.)[/url]
    ....

    > Thx, Seansan
    You could:

    use Regexp::Common::URI;

    --
    Bob Walton

    Bob Walton Guest

  7. #6

    Default Re: Matching URls

    Bob Walton wrote:

    ....
    > You could:
    >
    > use Regexp::Common::URI;
    >
    Make that:


    use Regexp::Common qw(URI);

    --
    Bob Walton

    Bob Walton Guest

  8. #7

    Default Re: Matching URls

    Thx JR (and others),

    I tried it, and it works. But I only have 1 problem:

    *) It matches all the text after the url as well."My String: "Homepage is @
    [url]http://www.homepage.nl[/url], yep thats it" becomes
    "Homepage is @ <A HREF=http://www.homepage.nl yep thats
    it>[url]http://www.homepage.nl[/url] yep thats it</A>"

    Any ideas on how to solve this? I played witht he regexp a while, but I cant
    figure it out.

    ps. How would I alter the regexp to match www. also? Like this?
    s/([http:\/\/www|www].*)\b/<a href='$1'>$1<\/a>/g;

    Seansan


    "JR" <jrolandumuc@yahoo.com> wrote in message
    news:b386d54b.0307200940.b8ef6b9@posting.google.co m...
    > "Seansan" <sheukels=cuthere=@yahoo.co.uk> wrote in message
    news:<3f1aa893$0$61643$e4fe514c@dreader3.news.xs4a ll.nl>...
    > > Hi,
    > >
    > > Does anyone know of a link to or an example of a decent regexp that wil
    > > recognize internet URLs? (It needs to match urls starting with http://
    and
    > > [url]www.)[/url]
    > >
    > > I am trying to replace a string like
    > > "My Homepage is @ http://www.homepage.nl"
    > > with
    > > "My Homepage is @ <A HREF =
    > > 'http://www.homepage.nl'>http://www.homepage.nl</A>"
    > >
    > > Thx, Seansan
    >
    > ## I think this is what you want. Good luck.
    > ## JR
    >
    > #!/perl
    > use strict;
    > use diagnostics;
    > use warnings;
    >
    > while(<DATA>) {
    > s/(http:\/\/www.*)\b/<a href='$1'>$1<\/a>/g;
    > print $_, "\n";
    > }
    >
    > __DATA__
    > My homepage is @ [url]http://www.homepage.nl[/url]
    > My favorite site is @ [url]http://www.espn.com[/url]
    > My second most favorite site is @ [url]http://www.whatever.org[/url]
    >
    > =pod
    > ## OUTPUT
    >
    > My homepage is @ <a
    href='http://www.homepage.nl'>http://www.homepage.nl</a>
    > My favorite site is @ <a
    > href='http://www.espn.com'>http://www.espn.com</a>
    > My second most favorite site is @ <a
    > href='http://www.whatever.org'>http://www.whatever.org</a>
    >
    > =cut

    Seansan Guest

  9. #8

    Default Re: Matching URls

    "Seansan" <sheukels=cuthere=@yahoo.co.uk> wrote in message news:<3f1aa893$0$61643$e4fe514c@dreader3.news.xs4a ll.nl>...
    > Hi,
    >
    > Does anyone know of a link to or an example of a decent regexp that wil
    > recognize internet URLs? (It needs to match urls starting with http:// and
    > [url]www.)[/url]
    Check out the Regexp::Common module. I think it has what you are looking for.
    >
    > I am trying to replace a string like
    > "My Homepage is @ http://www.homepage.nl"
    > with
    > "My Homepage is @ <A HREF =
    > 'http://www.homepage.nl'>http://www.homepage.nl</A>"
    >
    > Thx, Seansan
    Patrick LeBoutillier Guest

  10. #9

    Default Re: Matching URls

    Seansan (sheukels=cuthere=@yahoo.co.uk) wrote on MMMDCX September
    MCMXCIII in <URL:news:3f1aa893$0$61643$e4fe514c@dreader3.news. xs4all.nl>:
    \\ Hi,
    \\
    \\ Does anyone know of a link to or an example of a decent regexp that wil
    \\ recognize internet URLs? (It needs to match urls starting with http:// and
    \\ [url]www.)[/url]
    \\
    \\ I am trying to replace a string like
    \\ "My Homepage is @ http://www.homepage.nl"
    \\ with
    \\ "My Homepage is @ <A HREF =
    \\ 'http://www.homepage.nl'>http://www.homepage.nl</A>"


    use Regexp::Common qw /URI/;

    $str =~ s!($RE{URI}{HTTP})!<a href = '$1'>$1</a>!g;


    Abigail
    --
    perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
    ..qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
    ..qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
    %$^U;$^V/=$^U}while$^V!=$^W'
    Abigail Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139