How to remove the regular expression dollar format

I am trying to remove the dollar format from the string '$ 1,109,889.23'. I tried using regex with:

"[^\\d]" 

but then I get commas.

Any help? Thanks in advance.

+3
source share
8 answers

I am using ColdFusion. [^ \ D.] Works great as the eldarerathath mentioned above.

   <cfset amt = '$1,109,889.23'>
   <cfset newAmt = ReReplace(amt, "[^\d.]", "","ALL") >
   <cfoutput>#newAmt#</cfoutput>
+2
source

You do not need regex for this.

Just use lsParseCurrency:

numericValue = lsParseCurrency('$1,109,889.23'); writeOutput(numericValue);

An example on trycf.com gives:

1109889.23

Leigh ... yer locale - , , . ()... , :

numericValue = lsParseCurrency('$1,109,889.23', 'en_us');

+7

, $?

.

[^\d.]+

+2

$ ( " " " ", ), \$. , ?

0

[\d,.]+ . - Rubular.

0

? ^\$

0

, , , , , "1,109,889.23". , use [\d,.\x20]+ ( , , , \x20, , ), . , , , [^\d,.\x20]. This will work for any currency format, not just those that use the dollar sign. It also allows for several types of punctuation, for example, allowing spaces to separate multiple numbers instead of commas. However, I agree with Tim Pitzker that regex may not be the best tool for this job.

0
source

In Java:

String newString = oldString.replaceAll("$", "");
0
source

Source: https://habr.com/ru/post/1778379/


All Articles