|
Mailing Lists
|
Home /
Groups /
Regular Expressions (RegEx)
Search box, phrases and single words
Hi All,Developer MediaDoc 10/31/08 02:32 P > The SQL part we have. And I have a RegEx that works beautifully - but onlyPeter Boughton 10/31/08 02:43 P Ah! I just noticed - you've got a stray whitespace at the end of yourPeter Boughton 10/31/08 02:44 P Hi All, We have a search box on our site. Want users to be able to type things like "Healthy Children" Canada Nutrition and our SQL to loop over and look for "Healthy Children" OR Canada OR Nutrition The SQL part we have. And I have a RegEx that works beautifully - but only if someone enters a phrase (in quotes). Our code is: <cfset my_reg_ex = "(?:""([^""]+)"")|([^ ]+) "> <cfset my_search_terms_array = REMatch (my_reg_ex, FORM.searchString)> ... then our SQL to loop over the array that REMatch creates. Any help on why the RegEx does NOT work (it always misses the last word in the FORM.searchString (i.e. our array is always one short!). Many thanks, Matts ----- Excess quoted text cut - see Original Post for more ----- Works fine here - but do yourself a favour and don't use escaped double-quotes... cfsavecontent makes it easier to read (or use single quotes). Here is the test code that works for me: <cfsavecontent variable="Input1">"Healthy Children" Canada Nutrition</cfsavecontent> <cfsavecontent variable="Input2">Healthy Children Canada Nutrition</cfsavecontent> <cfsavecontent variable="Input3">Healthy Children "Canada Nutrition"</cfsavecontent> <cfsavecontent variable="Input4">"Healthy Children Canada Nutrition"</cfsavecontent> <cfsavecontent variable="Input5">"Healthy Children" "Canada Nutrition"</cfsavecontent> <cfsavecontent variable="Rex">(?:"([^"]+)")|([^ ]+)</cfsavecontent> <cfdump var="#rematch( Rex , Input1 )#" /> <cfdump var="#rematch( Rex , Input2 )#" /> <cfdump var="#rematch( Rex , Input3 )#" /> <cfdump var="#rematch( Rex , Input4 )#"/> <cfdump var="#rematch( Rex , Input5 )#"/> Ah! I just noticed - you've got a stray whitespace at the end of your expression - my code has removed that whitespace. That's why the last one is failing for you. Many thanks Peter, for both noticing the stray whitespace AND for the cfsavecontent tag... never used that one before... I agree makes it MUCH easier to read! Cheers, Matts >Ah! I just noticed - you've got a stray whitespace at the end of your >expression - my code has removed that whitespace. That's why the last one is >failing for you.
|
May 20, 2013
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||