本文介绍了如何从字符串中删除除$后跟任何数字的所有字符?字符串应仅包含$ 26272,即[美元] [数字]格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过这个

value.replace(/ [^ \ $ \d *] / g,'');



它取代了所有字母,特殊字符等。但如果输入额外的$,则不会替换它。



例如如果输入值是$ 686 $ 7它没有替换6和7之间的$。



我需要的结果应该是$ 6867



如果输入为$$,则结果应为$



如果输入为$ 676 $ o / p应为$ 676



如果输入为$ 676 $ o / p应为$ 676

如果输入为$ 676h $ o / p应为$ 676



我尝试过:



value.replace(/ [^ \ $ \ * *] / g,'');

I have tried this
value.replace(/[^\$\d*]/g, '');

Its replacing all letter, special character etc. But If extra $ is given as input it is not replacing it.

e.g. If the input value is $686$7 It is not replacing the $ between 6 and 7.

I need the result should like be $6867

If the input is $$ the result should be $

If the input is $676$ o/p should be $676

If the input is $676$ o/p should be $676
If the input is $676h$ o/p should be $676

What I have tried:

value.replace(/[^\$\d*]/g, '');

推荐答案




这篇关于如何从字符串中删除除$后跟任何数字的所有字符?字符串应仅包含$ 26272,即[美元] [数字]格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 13:46