Skip to main content
Inspiring
July 26, 2011
Question

cf extract substring after url

  • July 26, 2011
  • 1 reply
  • 766 views

While loopong through query results I am trying to extract the page name from a url.

From this sample url -------  http://www.cnn.com/sports.cfm

I want to extract the name sports.cfm  only

or

From this sample url -------  http://www.msnbc.com/shows.asp

I want to extract the name shows.asp  only

    This topic has been closed for replies.

    1 reply

    Owainnorth
    Inspiring
    July 26, 2011

    I'll give you a clue - think of the string as a list, separated by forward slashes

    Inspiring
    July 26, 2011

    Have you checked CFLIB.ORG?  I think there are number of variations on a function that parses out the parts of a URL.  Also, along Owain's comment, is what I usually do:  Use a CF list function with a delimiter of ? to get the "left" part of a URL, then whack a possible trailing / at the end of what's left, then use a CF list function with a delimiter of / to get the last element of the list.

    Many of the CFLIB functions use a regex.  I think that the CFWACK books even use a URL parsing example to show how to use CF regex functions.

    -reed