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

Search regex

July 04, 2009

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

Home /  Groups /  Regular Expressions (RegEx)

Convert string to html file name

  << 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:
DougF
11/12/2003 02:38 PM

Thanks Peter, Works great except when the string has any number of trailing non-alphanumeric characters. Adds a dash to the end of the string. Should have said '-remove any leading or trailing non-alphanumeric characters' instead of  '-return string with both leading and trailing spaces removed'. e.g. [yellow!] results in [yellow-} e.g. [yellow !} results in [yellow-} Any suggestions? DougF ----- Excess quoted text cut - see Original Post for more ----- doesn't quite catch everything. ----- Excess quoted text cut - see Original Post for more ----- (bens)], > -remove all non-alphanumeric and punctuation characters, > -replace single or multiple spaces with a single dash [eg. (white rose) becomes (white-rose)]. > -replace a punctuation character with a fore and aft by space with a single dash with no spaces [eg. (ben & jerry) becomes (ben-jerry)].

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Ben Doom
11/12/2003 02:55 PM

Try breaking the line str = REReplace(str,"^[^[:alnum:]]*(.*)[^[:alnum:]]*$","\1"); into str = rereplace(str, "^[^[:alnum:]]*", ""); str = rereplace(str, "[^[:alnum:]]*$", ""); It's the ever-present greedy match problem from CF5.  :-) --Ben Doom DougF wrote: ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
DougF
11/12/2003 03:27 PM

That got it! thanks, DougF -------------- Final solution: -------------- function HTMLFileName(str){ // replace leading and trailing characters str = rereplace(str,"^[^[:alnum:]]*", ""); // remove trailing non-alphanumeric characters str = rereplace(str,"[^[:alnum:]]*$", ""); // remove apostrophies str = Replace(str,"'","","ALL"); // replace groups of non alphanumerical with dashes str = REReplace(str,"[^[:alnum:]]+","-","ALL"); // to lower case str = LCase(str)& ".html"; return str; } #HTMLFileName("#string#")# ----- Excess quoted text cut - see Original Post for more -----

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Pascal Peters
11/13/2003 03:33 AM

As I said, I didn't test. I wrote it from home during a holiday. Ben is right. This is also the reason why, in my opinion, you can't do it in one run. I don't think you can remove leading and trailing characters AND replace the others with - Pascal Try breaking the line str = REReplace(str,"^[^[:alnum:]]*(.*)[^[:alnum:]]*$","\1"); into str = rereplace(str, "^[^[:alnum:]]*", ""); str = rereplace(str, "[^[:alnum:]]*$", ""); It's the ever-present greedy match problem from CF5.  :-) --Ben Doom DougF wrote:

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Cantrell, Adam
11/13/2003 12:40 PM

Great timing on this. I was trying to do something similar this morning, then opened up this list and here's the answer. But does anyone get an error running this on a string with multiple apostrophes? I'm using MX. Adam's File Name (works fine). Adam's Tester's File Name ('Error Occurred While Processing Request' - no description of the error in the debug) Adam. That got it! thanks, DougF -------------- Final solution: -------------- function HTMLFileName(str){ // replace leading and trailing characters str = rereplace(str,"^[^[:alnum:]]*", ""); // remove trailing non-alphanumeric characters str = rereplace(str,"[^[:alnum:]]*$", ""); // remove apostrophies str = Replace(str,"'","","ALL"); // replace groups of non alphanumerical with dashes str = REReplace(str,"[^[:alnum:]]+","-","ALL"); // to lower case str = LCase(str)& ".html"; return str; } #HTMLFileName("#string#")# ----- Excess quoted text cut - see Original Post for more -----

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Pascal Peters
11/13/2003 02:12 PM

I can't see why it would do that. The apostrophes are removed with a simple replace, not by a regexp. Have you tried taking ou the line to see what happens? If you don't find a solution, I will try to debug this tomorow morning (when I've got the server running) Pascal   -----Oorspronkelijk bericht-----   Van: Cantrell, Adam [mailto:Acantrell@kentlaw.edu]   Verzonden: do 13/11/2003 18:37   Aan: CF-RegEx   CC:   Onderwerp: RE: Convert string to html file name         Great timing on this. I was trying to do something similar this morning,   then opened up this list and here's the answer.      But does anyone get an error running this on a string with multiple   apostrophes? I'm using MX.      Adam's File Name (works fine).   Adam's Tester's File Name ('Error Occurred While Processing Request' - no   description of the error in the debug)      Adam.        Sent: Wednesday, November 12, 2003 2:24 PM   To: CF-RegEx   Subject: Re: Convert string to html file name      That got it!   thanks,   DougF   --------------   Final solution:   --------------   function HTMLFileName(str){   // replace leading and trailing characters   str = rereplace(str,"^[^[:alnum:]]*", "");   // remove trailing non-alphanumeric characters   str = rereplace(str,"[^[:alnum:]]*$", "");   // remove apostrophies   str = Replace(str,"'","","ALL");   // replace groups of non alphanumerical with dashes   str = REReplace(str,"[^[:alnum:]]+","-","ALL");   // to lower case   str = LCase(str)& ".html";   return str;   }   #HTMLFileName("#string#")#     To: "CF-RegEx" <RegEx@houseoffusion.com>   Sent: Wednesday, November 12, 2003 11:52 AM   Subject: Re: Convert string to html file name      > Try breaking the line   > str = REReplace(str,"^[^[:alnum:]]*(.*)[^[:alnum:]]*$","\1");   > into   > str = rereplace(str, "^[^[:alnum:]]*", "");   > str = rereplace(str, "[^[:alnum:]]*$", "");   >   > It's the ever-present greedy match problem from CF5.  :-)   >   > --Ben Doom         _____     

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Cantrell, Adam
11/13/2003 04:09 PM

Yeah, sorry about that. The function is fine. It had something to do with the way I was processing the XML I was pulling the string out of. Thanks again. Adam. I can't see why it would do that. The apostrophes are removed with a simple replace, not by a regexp. Have you tried taking ou the line to see what happens? If you don't find a solution, I will try to debug this tomorow morning (when I've got the server running) Pascal -----Oorspronkelijk bericht----- Van: Cantrell, Adam [mailto:Acantrell@kentlaw.edu] Verzonden: do 13/11/2003 18:37 Aan: CF-RegEx CC: Onderwerp: RE: Convert string to html file name Great timing on this. I was trying to do something similar this morning, then opened up this list and here's the answer. But does anyone get an error running this on a string with multiple apostrophes? I'm using MX. Adam's File Name (works fine). Adam's Tester's File Name ('Error Occurred While Processing Request' - no description of the error in the debug) Adam. That got it! thanks, DougF -------------- Final solution: -------------- function HTMLFileName(str){ // replace leading and trailing characters str = rereplace(str,"^[^[:alnum:]]*", ""); // remove trailing non-alphanumeric characters str = rereplace(str,"[^[:alnum:]]*$", ""); // remove apostrophies str = Replace(str,"'","","ALL"); // replace groups of non alphanumerical with dashes str = REReplace(str,"[^[:alnum:]]+","-","ALL"); // to lower case str = LCase(str)& ".html"; return str; } #HTMLFileName("#string#")# ----- Excess quoted text cut - see Original Post for more -----   _____  


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

Mailing Lists