+ Reply to Thread
Results 1 to 7 of 7

Extract URL from string

  1. #1
    Forum Contributor
    Join Date
    04-13-2017
    Location
    Buchares
    MS-Off Ver
    2016
    Posts
    117

    Question Extract URL from string

    Hello, I have a question regarding the possibility of extracting the URL and display it (example msgbox, or debug.print) from different sets of strings

    The easy cases ?
    "Hey , enter here www.google.com" -> the site will be "www.google.com"
    "Hey , enter here http://www.google.com" -> the site will be "http://www.google.com"

    But the hard cases for example would be
    1) Images
    "Hey , check out this image https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" and the link would be the entire image "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png"

    2) Direct Links
    "hey enter here google.com" -> the site will be "google.com"

    For the easy cases i would have an idea about to search for www. or http in string and search for the first empty space? i think...but for the hard cases?

    Thank you
    Attached Files Attached Files

  2. #2
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Extract URL from string

    You could try using regular expressions to extract the URL:

    Please Login or Register  to view this content.
    See attached.

    WBD
    Attached Files Attached Files
    Office 365 on Windows 11, looking for rep!

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Extract URL from string


    Please be aware that looking for www is a red herring, as it is an arbitrary convention and not a standard. A URL for a web page doesn't have to start with www (ex: https://boards.straightdope.com/sdmb/index.php)

    WBD, I get a #NAME error for this sample input:

    My album is at http://www.seiglefamily.com/photos.php?dir=2018alaska&cols=1&cappos=right&ppp=10

    but I haven't dissected your regexp yet to figure out why. (But the OP may not care about a case like this.)
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Extract URL from string

    Quote Originally Posted by 6StringJazzer View Post
    Please be aware that looking for www is a red herring, as it is an arbitrary convention and not a standard. A URL for a web page doesn't have to start with www (ex: https://boards.straightdope.com/sdmb/index.php)

    WBD, I get a #NAME error for this sample input:

    My album is at http://www.seiglefamily.com/photos.php?dir=2018alaska&cols=1&cappos=right&ppp=10

    but I haven't dissected your regexp yet to figure out why. (But the OP may not care about a case like this.)
    Yep. A solid regular expression would probably run into hundreds of characters. I was aiming at the provided examples only. Complex URLs with parameters won't work with the above.

    WBD

  5. #5
    Forum Contributor
    Join Date
    04-13-2017
    Location
    Buchares
    MS-Off Ver
    2016
    Posts
    117

    Re: Extract URL from string

    Hey Jeff,
    After receiving the RegExp i've tested over ~30 cases that i would think that would break the normal flow of the code but didn't find anything that raised any concerns. Also i've tested again your code and worked perfectly on my side (see picture attached)

    I know that searching for arbitrary convention is not a good manner but i didn't had any idea at the moment so i asked here

    Thank you for your time explaining every detail. It has been noted down.



    For further info:
    I am using the latest update available for office 2016 x86 system on Windows 10 Pro x64.

    Thank you for your time
    Attached Images Attached Images

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Extract URL from string

    That is interesting. Excel 2013 on Windows 10 Pro x64.
    namerror.JPG

  7. #7
    Forum Contributor
    Join Date
    04-13-2017
    Location
    Buchares
    MS-Off Ver
    2016
    Posts
    117

    Re: Extract URL from string

    Quote Originally Posted by 6StringJazzer View Post
    That is interesting. Excel 2013 on Windows 10 Pro x64.
    Attachment 590281
    I'm back with another test, 6StringJazzer, tested on the latest Excel 2016 x64 on Windows 10 Pro x64. on a virtual machine, works like a glove.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Formula to search a range for a string and then extract certain dta from string
    By gratedane8 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-08-2018, 06:09 PM
  2. [SOLVED] extract multi-letter string bits from string depending on size and case
    By luv2glyd in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 02-18-2017, 10:41 PM
  3. Replies: 4
    Last Post: 10-25-2016, 04:45 PM
  4. [SOLVED] Extract all the words from a string for processing, while leaving string intact.
    By staggers47 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 10-10-2014, 02:02 PM
  5. [SOLVED] Extract a mainly numeric string (ISSN number) from an arbitrary string
    By Buzzed Aldrin in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 07-04-2012, 01:49 PM
  6. Replies: 16
    Last Post: 10-11-2011, 12:31 PM
  7. Extract small string of text from larger string
    By mark_jam3s in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-23-2010, 05:36 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1