Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Url regex

Guest
Feb 12, 2010 Feb 12, 2010

Is there a way to be able to do the following, lets say i get passed the following url:

htttp://www.amazon.com?type=books&sessionid=1234

And i want to be able to strip it and only get the following:

www.amazon.com

393
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 12, 2010 Feb 12, 2010

Yep.

Have a look at rereplace():

http://livedocs.adobe.com/coldfusion/8/htmldocs/functions_m-r_35.html#135742

And how regular expressions work:

http://livedocs.adobe.com/coldfusion/8/htmldocs/regexp_01.html#1100400

Or a slightly obtuse way would be to treat the URL like a slash-delimited list, and the domain name would be the second element.

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 12, 2010 Feb 12, 2010
LATEST

Or a slightly obtuse way would be to treat the URL like a slash-delimited list, and the domain name would be the second element.

Of course this only works if you have a file part to your URL, which in your case you do not.

So you could treat it as a "/?" delimited list instead.

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2010 Feb 12, 2010

To start with, I am assuming there's been a typo, and you mean http. Then you can solve the problem the old-fashioned way.

Treat the URL as a string of the form:

http://xxx?yyy

where xxx is the part you want. You can consider the symbol ? as a delimiter of a list that consists of the 2 elements, http://xxx and yyy. All that is left is for you to strip off http://

<cfset urlString="http://www.amazon.com?type=books&sessionid=1234">
<cfset domain = listGetAt(urlString,1,"?")>
<cfset www = replaceNoCase(domain, "http://", "")>
<cfoutput>#www#</cfoutput>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources