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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Posts: 10
Joined: Mon Jan 03, 2022 7:10 pm


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

Posts: 12948
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany

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



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

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

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”