Re: REreplace function for special characters
[q] FileName = rereplace(FileName, '(?!\.[^.]*$)\W', '', 'all') [/q] well, that is just beautiful! Azadi Saryev Sabai-dee.com http://www.sabai-dee.com/ ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:316752 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: REreplace function for special characters
hmm... i guess i forgot to paste in the rest of the code... here it is in all its ugly gory: cfset filename = rereplace(left(filename, len(filename)-len(listlast(filename, .))-1), \W, , all) . listlast(filename, .) it may be eugh and ugly!, but it's a one-liner and takes care of . inside filenames and any file extension length :) if you still feel eugh about that one, how about this one: cfset filename = reverse(rereplace(listrest(reverse(filename), .), \W, , all)) . listlast(filename, .) since this one is a tad bit shorter, will you consider it, maybe, just ugly or just eugh? :) or how about this rereplace-only one: cfset filename = rereplace(rereplace(filename, (.+?)(\.[^.]*$|$), \1), \W, , all) rereplace(filename, (.+?)(\.[^.]*$|$), \2) (filename splitting regex courtesy of http://www.movingtofreedom.org/2008/04/01/regex-match-filename-base-and-extension/) :P Azadi Saryev Sabai-dee.com http://www.sabai-dee.com/ Peter Boughton wrote: better then just do something like rereplace(left(filename, len(filename)-len(listlast(filename, .)-1), \W, , all) Eugh. Ugly! And doesn't restore the extension afterwards, so my-image-name.png would become myimagename instead of myimagename.png. ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:316687 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: REreplace function for special characters
but it's a one-liner So? Unless you have a limited number of newlines, mindlessly shoving commands into a single line is really dumb; it reduces readability and achieves nothing. This is another thing that bugs me - people compressing code without thought - having the right amount of whitespace in the right places is good for you! takes care of . inside filenames and any file extension length Well yeah, the original spec was dealing with images, which in general have a limited set of extensions, so extension length wasn't so much an issue. But yes, something to work for all filenames could be useful to people. All the ones you gave, (aside from being /UGLY/ :P), will not work for several common filenames - try running .htaccess and README through them, for example. Of course, I have come up with a one-line solution, but not by shunting together multiple commands. :P FileName = rereplace( FileName , '(?!\.[^.]*$)\W' , '' , 'all' ) Strips all non-word characters, excluding the final dot (if any). Although, thinking a bit more... for general purpose use, I might not bother stripping dots, or hyphens, or tilde, so might end up with this instead: FileName = rereplace( FileName , '(?!\.[^.]|[-~])\W' , '' , 'all' ) ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:316730 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: REreplace function for special characters
better then just do something like rereplace(left(filename, len(filename)-len(listlast(filename, .)-1), \W, , all) Eugh. Ugly! And doesn't restore the extension afterwards, so my-image-name.png would become myimagename instead of myimagename.png. ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:316611 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: REreplace function for special characters
My follow-up posted last night didn't show up. So, I'm re-doing it now. Execellent, Peter, thank you very much. I'll use rereplace( FileName , '\W' , '' , 'all' ) On the extension stuff I have a way to address it. Don rereplace(foo, '[^\w]', '', 'all') will replace any non-alphanumeric character No need to complicate things with an inverted character class. \W is same as [^\w] Also, this bugs me immensely: assuming 'foo' is the file name JUST USE THE VARIABLE FILENAME THEN! So: rereplace( FileName , '\W' , '' , 'all' ) ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:316653 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
REreplace function for special characters
Regular Expression gurus. How to use the REreplace function to remove special characters including +, . in an image file name? The ReplaceList function may miss some unexpected special characters for we don't know what sort of special character may show up in a dynamically generated image file with special characters. Many thanks. ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:316577 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: REreplace function for special characters
rereplace(foo, '[^\w]', '', 'all') will replace any non-alphanumeric character in 'foo' (assuming 'foo' is the file name). On Wed, Dec 10, 2008 at 1:41 PM, Don L [EMAIL PROTECTED] wrote: Regular Expression gurus. How to use the REreplace function to remove special characters including +, . in an image file name? The ReplaceList function may miss some unexpected special characters for we don't know what sort of special character may show up in a dynamically generated image file with special characters. Many thanks. ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:316579 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: REreplace function for special characters
rereplace(foo, '[^\w]', '', 'all') will replace any non-alphanumeric character in 'foo' (assuming 'foo' is the file name). On Wed, Dec 10, 2008 at 1:41 PM, D Great. Thank you. I also found out that REreplace(str, [^a-zA-Z0-9],,all) would achieve the same result but yours seems more elegant (which seems to say just keep {words}), my CF env = cf8 or cf81 for Windows, does your solution have any dependency? ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:316581 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: REreplace function for special characters
rereplace(foo, '[^\w]', '', 'all') will replace any non-alphanumeric character No need to complicate things with an inverted character class. \W is same as [^\w] Also, this bugs me immensely: assuming 'foo' is the file name JUST USE THE VARIABLE FILENAME THEN! So: rereplace( FileName , '\W' , '' , 'all' ) ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:316582 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: REreplace function for special characters
On Wed, Dec 10, 2008 at 3:02 PM, Peter Boughton [EMAIL PROTECTED] wrote: rereplace(foo, '[^\w]', '', 'all') will replace any non-alphanumeric character No need to complicate things with an inverted character class. \W is same as [^\w] fair enough. good catch. Also, this bugs me immensely: assuming 'foo' is the file name JUST USE THE VARIABLE FILENAME THEN! So: rereplace( FileName , '\W' , '' , 'all' ) bah. i like foo :P -- I have failed as much as I have succeeded. But I love my life. I love my wife. And I wish you my kind of success. ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:316584 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: REreplace function for special characters
Hmmm, another thought... Don, when you say image file name, is there a file extension to worry about (i.e. jpg/png/etc) If so, you'll want to be doing something like this... rereplace( FileName , '(png|jpg|gif|tif|bmp)$' , '.\0' ) after the initial replacement, to restore the dot that will otherwise be stripped. (If you're manually adding the extension later, it doesn't matter) ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:316585 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: REreplace function for special characters
I also found out that REreplace(str, [^a-zA-Z0-9], ,all) would achieve the same result but yours seems more elegant (which seems to say just keep {words}), my CF env = cf8 or cf81 for Windows, does your solution have any dependency? No dependency. \W [^\w] and [^a-zA-Z0-9] will all work in all CFML versions/engines worth worrying about They are all standard regex constructs. However, it is worth pointing out that \w has a slightly different meaning amongst different regex engines - it means word character, rather than alphanumeric. In CFML/rereplace it is treated as [a-zA-Z0-9_] (not the underscore). However, in some flavours of regex \w will accept accented/etc characters (e.g. á ç ÿ ) - so if this code was used in something other than CFML, you might need to use the version that explicitly specifies standard letters+digits. ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:316586 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: REreplace function for special characters
Sorry, typo. :( In CFML/rereplace it is treated as [a-zA-Z0-9_] (not the underscore). That should say note rather than not. Underscore is included in \w (and excluded from \W) which is not what some people might expect/want. ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:316587 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: REreplace function for special characters
better then just do something like rereplace(left(filename, len(filename)-len(listlast(filename, .)-1), \W, , all) Azadi Saryev Sabai-dee.com http://www.sabai-dee.com/ Peter Boughton wrote: Hmmm, another thought... Don, when you say image file name, is there a file extension to worry about (i.e. jpg/png/etc) If so, you'll want to be doing something like this... rereplace( FileName , '(png|jpg|gif|tif|bmp)$' , '.\0' ) after the initial replacement, to restore the dot that will otherwise be stripped. (If you're manually adding the extension later, it doesn't matter) ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:316597 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4