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

Mailing Lists
Home /  Groups /  Regular Expressions (RegEx)

Search box, phrases and single words

  << 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:
Developer MediaDoc
10/31/2008 02:32 PM

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

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Peter Boughton
10/31/2008 02:43 PM

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

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Peter Boughton
10/31/2008 02:44 PM

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.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Developer MediaDoc
11/12/2008 04:27 PM

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.


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

Search regex

May 20, 2013

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

Designer, Developer and mobile workflow conference