|
Mailing Lists
|
Home /
Groups /
Regular Expressions (RegEx)
Convert string to html file
Hi all,Douglas Fentiman 11/12/03 02:39 A I think you will need multiple runsPascal Peters 11/12/03 03:59 A I'm not sure it's *necessary* to do it in multiple runs, but it sureBen Doom 11/12/03 09:38 A Any appreciable advantage to decreasing the number of runs?DougF 11/12/03 03:23 P Well, in theory, you save processor time by not restarting the regexBen Doom 11/12/03 03:53 P Hi all, Any suggestions on converting a string into a HTML file name. My attempt doesn't quite catch everything. (using CF5) Thanks, DougF ------------------- RegExp Requirements: -return string with both leading and trailing spaces removed, -return string in lower case, -first character must be alphanumeric, -words composing the string are separated by a dash, -words separated by punctuation to be separated by a dash, -remove apostrophies within or surrounding words [eg. ('ben's') becomes (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)]. My RegExp attempt: #trim(Lcase(REReplace(REReplace("#string#","[[:punct:]]|[[:space:]]","+","all"),"[+]+","-","all")))#.html String Examples with result below: Circle "S" Ranch [circle-s-ranch] - OK 'Chicken' & Foy's Graphics - Dallas/Texas [-chicken-foy-s-graphics-dallas-texas.html] - No Good. Leading dash and dash between foy and s. Should return [chicken-foys-graphics-dallas-texas.html] "Graphics@Roy's" [-graphics-roy-s-.html] - No Good. Leading and trailing dash and dash between roy and s. I think you will need multiple runs function HTMLFileName(str){ // replace leading and trailing characters str = REReplace(str,"^[^[:alnum:]]*(.*)[^[:alnum:]]*$","\1"); // 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; } Haven't tested it HTH Pascal -----Oorspronkelijk bericht----- Van: Douglas Fentiman [mailto:df8833@shaw.ca] Verzonden: wo 12/11/2003 7:38 Aan: CF-RegEx CC: Onderwerp: Convert string to html file Hi all, Any suggestions on converting a string into a HTML file name. My attempt doesn't quite catch everything. (using CF5) Thanks, DougF ------------------- RegExp Requirements: -return string with both leading and trailing spaces removed, -return string in lower case, -first character must be alphanumeric, -words composing the string are separated by a dash, -words separated by punctuation to be separated by a dash, -remove apostrophies within or surrounding words [eg. ('ben's') becomes (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)]. I'm not sure it's *necessary* to do it in multiple runs, but it sure would be a heck of a lot easier. :-) I agree with Pascal, and it looks like his scheme should run fine. --Ben Doom Pascal Peters wrote: ----- Excess quoted text cut - see Original Post for more ----- Any appreciable advantage to decreasing the number of runs? DougF > I'm not sure it's *necessary* to do it in multiple runs, but it sure > would be a heck of a lot easier. :-) > > I agree with Pascal, and it looks like his scheme should run fine. > > --Ben Doom Well, in theory, you save processor time by not restarting the regex engine. On the other hand, I have doubts as to whether in reality you save much if your regex becomes much more complicated. Also, you have to balance "I have time to write this" against "it saves a millicecond per 100 page loads", you know? When you get down to it, if it's not much harder to do it in 1 regex, I do it that way. If it's going to take 3 hours to write and debug 1 regex, and 1 hour to write and debug 3, I just use 3 runs. A handful of times saving 2 hours like that and the time/money ratio works out to a new low-end server. :-) --Ben Doom DougF wrote: ----- Excess quoted text cut - see Original Post for more -----
|
May 25, 2012
|
Latest Fusion Authority Articles
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||