Page 1 of 1

URLComponents

Posted: Mon Jan 03, 2022 8:15 pm
by Emily-Elizabeth
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

Re: URLComponents

Posted: Mon Jan 03, 2022 8:42 pm
by Klaus
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.

Re: URLComponents

Posted: Thu Feb 03, 2022 12:25 am
by mwieder
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.