I'm looking for some REGEX help Given the following URL: http://news.cnet.com/8301-13924_3-10315534-64.html?part=rss&subj=news&tag=2547-1_3-0-20
What is the REGEX to obtain the following:
http://news.cnet.com/8301-13924_3-10315534-64.html
Thus removing the ? and everything after it
Thanks, B
You can certainly use a regex for this, but it would be more efficient to use
listfirst(theurl, '?')
which finds the first part of a list delimited by question marks.
In ColdFusion you could use regex replace:
myURL = REReplace(myURL,"\?.*$","")
That would leave you with everything before the question mark.
This regular expression will do the trick:
^([^?]+)
Just take the second capture group from the match (the first capture group is always the original string itself if it matched).
@Ben Doom: If I'm not mistaken, the #url# variable is a complex object and cannot be treated as a string or list. The way I go about getting everything before the query string is:
<cfset myURL = "http://" & #cgi.HTTP_HOST# & #cgi.SCRIPT_NAME# />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.