House of Fusion
Home of the ColdFusion Community

Search regex

November 22, 2008

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

Search over 2,500 ColdFusion resources here  >>>      
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 >> 

11/12/2003 02:38 PM
Author:
DougF

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 ----- Original Message ----- From: "Pascal Peters" <ppeters@lrt.be> To: "CF-RegEx" <RegEx@houseoffusion.com> Sent: Wednesday, November 12, 2003 12:56 AM Subject: RE: Convert string to html file doesn't quite catch everything. (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)]. > > > >

11/12/2003 02:55 PM
Author:
Ben Doom

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:

11/12/2003 03:27 PM
Author:
DougF

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#")# ----- Original Message ----- From: "Ben Doom" <bdoom@moonbow.com> To: "CF-RegEx" <RegEx@houseoffusion.com> Sent: Wednesday, November 12, 2003 11:52 AM Subject: Re: Convert string to html file name

11/13/2003 03:33 AM
Author:
Pascal Peters

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:

11/13/2003 12:40 PM
Author:
Cantrell, Adam

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#")# ----- Original Message ----- From: "Ben Doom" <bdoom@moonbow.com> To: "CF-RegEx" <RegEx@houseoffusion.com> Sent: Wednesday, November 12, 2003 11:52 AM Subject: Re: Convert string to html file name

11/13/2003 02:12 PM
Author:
Pascal Peters

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.      -----Original Message-----   From: DougF [mailto:df8833@shaw.ca]   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#")#   ----- Original Message -----   From: "Ben Doom" <bdoom@moonbow.com>   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         _____     

11/13/2003 04:09 PM
Author:
Cantrell, Adam

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#")# ----- Original Message ----- From: "Ben Doom" <bdoom@moonbow.com> To: "CF-RegEx" <RegEx@houseoffusion.com> Sent: Wednesday, November 12, 2003 11:52 AM Subject: Re: Convert string to html file name   _____  


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

Mailing Lists