|
Mailing Lists
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
RegEx: Grabbing Keywords from Referers
Author: Che Vilnonis
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:61830#336491
Thanks for the update Peter.
><cfset keywords = reMatchNoCase("[?|&][p|q]=[^&]+", referer)>
This is incorrect - the | is a literal in character classes.
You want [?&][pq]=[^&]+
Author: Peter Boughton
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:61830#336489
><cfset keywords = reMatchNoCase("[?|&][p|q]=[^&]+", referer)>
This is incorrect - the | is a literal in character classes.
You want [?&][pq]=[^&]+
Author: Andy Matthews
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:61830#336482
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"))>
Author: Che Vilnonis
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:61830#336481
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"))>
Author: Che Vilnonis
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:61830#336480
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 -----
Author: Andy Matthews
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:61830#336476
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 -----
Author: John M Bliss
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:61830#336475
> 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 -----
Author: Andy Matthews
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:61830#336474
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>
Author: John M Bliss
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:61830#336473
> I wonder if the regex gurus have a solution as well.
Oh, I'm sure. :-)
----- Excess quoted text cut - see Original Post for more -----
Author: Che Vilnonis
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:61830#336472
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
|
May 24, 2012
|
Latest Fusion Authority Articles
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||