|
|
Home /
Groups /
Regular Expressions (RegEx)
Convert string to html file name
Thanks Peter,DougF 11/12/03 02:38 P Try breaking the lineBen Doom 11/12/03 02:55 P That got it!DougF 11/12/03 03:27 P As I said, I didn't test. I wrote it from home during a holiday. Ben isPascal Peters 11/13/03 03:33 A Great timing on this. I was trying to do something similar this morning,Cantrell, Adam 11/13/03 12:40 P 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?Pascal Peters 11/13/03 02:12 P Yeah, sorry about that. The function is fine. It had something to do withCantrell, Adam 11/13/03 04:09 P 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)]. 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 ----- 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 ----- 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: 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 ----- 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 _____ 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 ----- _____
|
Mailing Lists
|
Latest Fusion Authority Articles
|
||||||