URLComponents

Bringing the internet highway into your project? Building FTP, HTTP, email, chat or other client solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Emily-Elizabeth
Posts: 101
Joined: Mon Jan 03, 2022 7:10 pm

URLComponents

Post by Emily-Elizabeth » Mon Jan 03, 2022 8:15 pm

This will take a URL and break it down to the different parts.

Code: Select all

function URLComponents pURL
   local tSchema, tAuthority, tPath, tQuery, tFragment, tTemp
   get matchText(pURL, "^(([^:\/?#]+):)?(\/?\/?([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$", tTemp, tSchema, tTemp, tAuthority, tPath, tTemp, tQuery, tTemp, tFragment)
   
   local tUserInfo, tHost, tPort
   get matchText(tAuthority, "(?:((?:[A-Za-z0-9\-._~!$&\'()*+,;=:]|%[0-9A-Fa-f]{2})*)@)?((?:[A-Za-z0-9\-._~!$&\'()*+,;=]|%[0-9A-Fa-f]{2})+)(?::([0-9]*))?", \
         tUserInfo, tHost, tPort)
   
   local tResults
   put tSchema into tResults["Schema"]
   put tUserInfo into tResults["UserInfo"]
   put tHost into tResults["Host"]
   put tPort into tResults["Port"]
   put tPath into tResults["Path"]
   put tQuery into tResults["Query"]
   put tFragment into tResults["Fragment"]
   
   return tResults
end URLComponents

Klaus
Posts: 13821
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: URLComponents

Post by Klaus » Mon Jan 03, 2022 8:42 pm

Hi Emily-Elizabeth,

welcome to the forum!

Thank you, and to what do we owe this honor? :D


Best

Klaus

P.S.
Personal note:
A little "Hello" or something would not have hurt for the very first posting.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: URLComponents

Post by mwieder » Thu Feb 03, 2022 12:25 am

Nice! That's some serious regex.
And I learned something new... I wasn't aware that you could reuse tTemp like that for the don't-care variables.

Post Reply

Return to “Internet”