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

Mailing Lists
Home /  Groups /  Regular Expressions (RegEx)

Convert string to html file

  << 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:
Douglas Fentiman
11/12/2003 02:39 AM

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.

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

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)].   

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Ben Doom
11/12/2003 09:38 AM

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

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

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

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

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


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

Search regex

May 25, 2012

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