House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  ColdFusion Talk (CF-Talk)

RegEx: Grabbing Keywords from Referers

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Che Vilnonis
08/23/2010 02:34 PM

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

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
John M Bliss
08/23/2010 02:38 PM

> I wonder if the regex gurus have a solution as well. Oh, I'm sure.  :-) ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Andy Matthews
08/23/2010 02:45 PM

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>

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
John M Bliss
08/23/2010 02:48 PM

> 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 -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Andy Matthews
08/23/2010 02:55 PM

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 -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Che Vilnonis
08/23/2010 03:42 PM

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 -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Che Vilnonis
08/23/2010 04:02 PM

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"))>

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Andy Matthews
08/23/2010 04:14 PM

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"))>

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Peter Boughton
08/24/2010 05:06 AM

><cfset keywords = reMatchNoCase("[?|&][p|q]=[^&]+", referer)> This is incorrect - the | is a literal in character classes. You want [?&][pq]=[^&]+

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Che Vilnonis
08/24/2010 08:45 AM

Thanks for the update Peter. ><cfset keywords = reMatchNoCase("[?|&][p|q]=[^&]+", referer)> This is incorrect - the | is a literal in character classes. You want [?&][pq]=[^&]+


<< Previous Thread Today's Threads Next Thread >>

Search cf-talk

February 04, 2012

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
       1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29