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: 1
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: 12685
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.

Post Reply

Return to “Internet”