|
Mailing Lists
|
Home /
Groups /
Regular Expressions (RegEx)
Convert string to html file name
Author: Cantrell, Adam
Short Link: http://www.houseoffusion.com/groups/regex/thread.cfm/threadid:118#667
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 -----
_____
Author: Pascal Peters
Short Link: http://www.houseoffusion.com/groups/regex/thread.cfm/threadid:118#666
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
_____
Author: Cantrell, Adam
Short Link: http://www.houseoffusion.com/groups/regex/thread.cfm/threadid:118#665
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 -----
Author: Pascal Peters
Short Link: http://www.houseoffusion.com/groups/regex/thread.cfm/threadid:118#664
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:
Author: DougF
Short Link: http://www.houseoffusion.com/groups/regex/thread.cfm/threadid:118#662
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 -----
Author: Ben Doom
Short Link: http://www.houseoffusion.com/groups/regex/thread.cfm/threadid:118#660
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 -----
Author: DougF
Short Link: http://www.houseoffusion.com/groups/regex/thread.cfm/threadid:118#659
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)].
|
May 25, 2012
|
Latest Fusion Authority Articles
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||