|
Mailing Lists
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
RegEx: Grabbing Keywords from Referers
Nice solution John. Thanks! Definitely different than mine.Che Vilnonis 08/23/10 02:34 P > I wonder if the regex gurus have a solution as well.John M Bliss 08/23/10 02:38 P This regex would search through a string and return all occurences ofAndy Matthews 08/23/10 02:45 P > Not sure where the second q= came from.John M Bliss 08/23/10 02:48 P Ah. The text was so small in my testing app that I couldn't tell what thatAndy Matthews 08/23/10 02:55 P Wow. That works very well. Thanks!Che Vilnonis 08/23/10 03:42 P Andy thanks again so much... this seems to work with Yahoo,Bing & Google.Che Vilnonis 08/23/10 04:02 P Awesome Che! Glad I could be of help!Andy Matthews 08/23/10 04:14 P ><cfset keywords = reMatchNoCase("[?|&][p|q]=[^&]+", referer)>Peter Boughton 08/24/10 05:06 A Thanks for the update Peter.Che Vilnonis 08/24/10 08:45 A Nice solution John. Thanks! Definitely different than mine. I wonder if the regex gurus have a solution as well. ;) This does (at least) Google. Shouldn't be too difficult to extrapolate the others... <cfloop index="thisarg" list="#cgi.HTTP_REFERER#" delimiters="?&"> <cfif ListFirst(thisarg, "=") is "q" and ListLen(thisarg, "=") is 2> <!--- then user searched for URLDecode(ListLast(thisarg, '=')) ---> <cfbreak> </cfif> </cfloop> > > I'm looking for a script to parse (yahoo,bing,google) keywords from > the cgi.http_referer variable preferrably done using CF's or a Java RegEx. > > Is there such a beast? > > TIA, Che > I wonder if the regex gurus have a solution as well. Oh, I'm sure. :-) ----- Excess quoted text cut - see Original Post for more ----- This regex would search through a string and return all occurences of q=followed by any character that's NOT an &. q=[^&]+ Given this string: http://www.google.com/search?source=ig&hl=en&rlz=&q=coldfusion&aq=f&aqi=g-p3 g7&aql=&oq=&gs_rfai=CJtNhsL9yTK_zHIWWhgTb-J3tDwAAAKoEBU_QXcSj It matches q=coldfusion q=f Not sure where the second q= came from. I just did a search on the Google homepage for "ColdFusion". andy Nice solution John. Thanks! Definitely different than mine. I wonder if the regex gurus have a solution as well. ;) This does (at least) Google. Shouldn't be too difficult to extrapolate the others... <cfloop index="thisarg" list="#cgi.HTTP_REFERER#" delimiters="?&"> <cfif ListFirst(thisarg, "=") is "q" and ListLen(thisarg, "=") is 2> <!--- then user searched for URLDecode(ListLast(thisarg, '=')) ---> <cfbreak> </cfif> </cfloop> > Not sure where the second q= came from. From this: &aq=f& On Mon, Aug 23, 2010 at 1:44 PM, Andy Matthews <lists@commadelimited.com>wrote: ----- Excess quoted text cut - see Original Post for more ----- Ah. The text was so small in my testing app that I couldn't tell what that was. Try this instead: [?|&]q=[^&]+ That only looks for q= when immediately following a ? or an &. Given the same string: http://www.google.com/search?q=coldfusion&source=ig&hl=en&rlz=&aq=f&aqi=g-p3 g7&aql=&oq=&gs_rfai=CJtNhsL9yTK_zHIWWhgTb-J3tDwAAAKoEBU_QXcSj It only matches ?q=coldfusion or &q=coldfusion > Not sure where the second q= came from. From this: &aq=f& On Mon, Aug 23, 2010 at 1:44 PM, Andy Matthews <lists@commadelimited.com>wrote: ----- Excess quoted text cut - see Original Post for more ----- Wow. That works very well. Thanks! Ah. The text was so small in my testing app that I couldn't tell what that was. Try this instead: [?|&]q=[^&]+ That only looks for q= when immediately following a ? or an &. Given the same string: http://www.google.com/search?q=coldfusion&source=ig&hl=en&rlz=&aq=f&aqi=g-p3 g7&aql=&oq=&gs_rfai=CJtNhsL9yTK_zHIWWhgTb-J3tDwAAAKoEBU_QXcSj It only matches ?q=coldfusion or &q=coldfusion > Not sure where the second q= came from. >From this: &aq=f& On Mon, Aug 23, 2010 at 1:44 PM, Andy Matthews <lists@commadelimited.com>wrote: ----- Excess quoted text cut - see Original Post for more ----- Andy thanks again so much... this seems to work with Yahoo,Bing & Google. My RegEx skills are a work in progress. <cfset referer = "http://search.yahoo.com/search;_ylt=Aqj24Omsi1LGKlDY4_G1hi6bvZx4?fr=yfp-t-7 01-s&toggle=1&cop=mss&ei=UTF8&p=children%20karate%20uniform"> <cfset keywords = reMatchNoCase("[?|&][p|q]=[^&]+", referer)> <cfset keywords = urlDecode(reReplace(keywords[1],"[?|&][p|q]=", "","ALL"))> Awesome Che! Glad I could be of help! andy Andy thanks again so much... this seems to work with Yahoo,Bing & Google. My RegEx skills are a work in progress. <cfset referer = "http://search.yahoo.com/search;_ylt=Aqj24Omsi1LGKlDY4_G1hi6bvZx4?fr=yfp-t-7 01-s&toggle=1&cop=mss&ei=UTF8&p=children%20karate%20uniform"> <cfset keywords = reMatchNoCase("[?|&][p|q]=[^&]+", referer)> <cfset keywords = urlDecode(reReplace(keywords[1],"[?|&][p|q]=", "","ALL"))> ><cfset keywords = reMatchNoCase("[?|&][p|q]=[^&]+", referer)> This is incorrect - the | is a literal in character classes. You want [?&][pq]=[^&]+ Thanks for the update Peter. ><cfset keywords = reMatchNoCase("[?|&][p|q]=[^&]+", referer)> This is incorrect - the | is a literal in character classes. You want [?&][pq]=[^&]+
|
February 04, 2012
|
Latest Fusion Authority Articles
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||