How to remove dollar format with regex

前端 未结 8 1918
北荒
北荒 2021-01-21 02:42

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

\"[^\\\\d]\" 

but then I ge

相关标签:
8条回答
  • 2021-01-21 02:52

    How about just doing a search and replace for , and $?

    but if you're going to do it.

    [^\d.]+

    0 讨论(0)
  • 2021-01-21 02:52

    Would this RegEx work for you?

    ^\$
    
    0 讨论(0)
  • 2021-01-21 02:56

    In Java:

    String newString = oldString.replaceAll("$", "");
    
    0 讨论(0)
  • 2021-01-21 03:01

    I am using ColdFusion. The [^\d.] works great as eldarerathis mentioned above.

       <cfset amt = '$1,109,889.23'>
       <cfset newAmt = ReReplace(amt, "[^\d.]", "","ALL") >
       <cfoutput>#newAmt#</cfoutput>
    
    0 讨论(0)
  • 2021-01-21 03:04

    [\d,.]+ would give you the number part. Here is your example on Rubular.

    0 讨论(0)
  • 2021-01-21 03:05

    Since $ is a metacharacter in regex (it means "end of string" or "end of line", depending on the current settings), it needs to be escaped to \$. But why use a regex at all if it's just one fixed character?

    0 讨论(0)
提交回复
热议问题