Regular Expression - decimal number positive negative
Heya, I know that some will know this quickly ... but I have ReplaceNoCase(str, [^0-9\.],,ALL) And this takes -5 to 5 ... which is not what I want - I want to include negative numbers what do I add to this regular expression to keep the decimals (if there) and keep the negative if there? So 5.24 is fine -5.24 is fine 5 is fine -5 if fine $5.24 (replace the $) $5,244.22 (replace the $ and the ,) Basically I need positive and negative integers to go into a float column. Thanks ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353457 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: Regular Expression - decimal number positive negative
So you need something like [^0-9\.-] This just adds the dash to your existing match. You could get a lot better though, like this -?\d+(\.\d+)? -? matches an optional negative indiator, aka a dash \d+ is just numbers, same as 0-9, the only part of this regex that is required (\.\d+)? means match a decimal only when it has numbers after it, and this entire group is optional nathan strutz [www.dopefly.com] [hi.im/nathanstrutz] [about.me/nathanstrutz] On Fri, Dec 14, 2012 at 7:59 AM, Paul Giesenhagen p...@quilldesign.comwrote: Heya, I know that some will know this quickly ... but I have ReplaceNoCase(str, [^0-9\.],,ALL) And this takes -5 to 5 ... which is not what I want - I want to include negative numbers what do I add to this regular expression to keep the decimals (if there) and keep the negative if there? So 5.24 is fine -5.24 is fine 5 is fine -5 if fine $5.24 (replace the $) $5,244.22 (replace the $ and the ,) Basically I need positive and negative integers to go into a float column. Thanks ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353458 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: Regular Expression - decimal number positive negative
A contrived, slightly expanded example based upon Nathan's code... cfscript samples = { a = 5.24, b = -5.24, c = 5, d = -5, e = $5.24, f = $5,244.22 }; for ( key in samples ) { writeOutput( reReplace( reReplace( samples[key], '(-?\d+(\.\d+)?)', '\1', 'all' ), '[^0-9\.-]', '', 'all' ) br / ); } /cfscript On Fri, Dec 14, 2012 at 9:14 AM, Nathan Strutz str...@gmail.com wrote: So you need something like [^0-9\.-] This just adds the dash to your existing match. You could get a lot better though, like this -?\d+(\.\d+)? -? matches an optional negative indiator, aka a dash \d+ is just numbers, same as 0-9, the only part of this regex that is required (\.\d+)? means match a decimal only when it has numbers after it, and this entire group is optional nathan strutz [www.dopefly.com] [hi.im/nathanstrutz] [about.me/nathanstrutz] On Fri, Dec 14, 2012 at 7:59 AM, Paul Giesenhagen p...@quilldesign.com wrote: Heya, I know that some will know this quickly ... but I have ReplaceNoCase(str, [^0-9\.],,ALL) And this takes -5 to 5 ... which is not what I want - I want to include negative numbers what do I add to this regular expression to keep the decimals (if there) and keep the negative if there? So 5.24 is fine -5.24 is fine 5 is fine -5 if fine $5.24 (replace the $) $5,244.22 (replace the $ and the ,) Basically I need positive and negative integers to go into a float column. Thanks ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353459 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: Regular Expression - decimal number positive negative
Recommend not reinventing the wheel here: http://www.cflib.org/udf/NumberUnFormat On 14 December 2012 14:59, Paul Giesenhagen p...@quilldesign.com wrote: Heya, I know that some will know this quickly ... but I have ReplaceNoCase(str, [^0-9\.],,ALL) And this takes -5 to 5 ... which is not what I want - I want to include negative numbers what do I add to this regular expression to keep the decimals (if there) and keep the negative if there? So 5.24 is fine -5.24 is fine 5 is fine -5 if fine $5.24 (replace the $) $5,244.22 (replace the $ and the ,) Basically I need positive and negative integers to go into a float column. Thanks ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353460 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
RE: Regular Expression - decimal number positive negative
Good deal ... thank you! -Original Message- From: Adam Cameron [mailto:adamcameroncoldfus...@gmail.com] Sent: Friday, December 14, 2012 9:28 AM To: cf-talk Subject: Re: Regular Expression - decimal number positive negative Recommend not reinventing the wheel here: http://www.cflib.org/udf/NumberUnFormat On 14 December 2012 14:59, Paul Giesenhagen p...@quilldesign.com wrote: Heya, I know that some will know this quickly ... but I have ReplaceNoCase(str, [^0-9\.],,ALL) And this takes -5 to 5 ... which is not what I want - I want to include negative numbers what do I add to this regular expression to keep the decimals (if there) and keep the negative if there? So 5.24 is fine -5.24 is fine 5 is fine -5 if fine $5.24 (replace the $) $5,244.22 (replace the $ and the ,) Basically I need positive and negative integers to go into a float column. Thanks ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353469 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm