正则表达式帮助:平衡 123,33 页。 => 123.33(双)
我是正则表达式的新手。
如何通过正则表达式将字符串解析
Balance 123,45 p.
为double
123.45
I'm new in regex..
How can I parse the string through regex
Balance 123,45 p.
to double
123.45
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
注意:不是基于正则表达式的解决方案。
对我来说,您获得的字符串似乎来自小数分隔符为
,
而不是.
的区域设置,您可以执行以下操作:Note: Not a Regex based solution.
To me it seems that the String that you are getting is from a locale where decimal separator is
,
instead of.
, you can just do something like this:您可以使用 String.split() 以
space
作为分隔符,然后使用 String.replaceAll() 将,
替换为.
。之后使用
输出=
123.45
You can use String.split() with
space
as a delimilter and than use String.replaceAll() to replace,
with.
.After that use parseDouble.It returns,
Output =
123.45
这将匹配零个或多个数字,后跟可选的逗号和一个或多个数字。例如:<代码>1,2345; 123; 12,34; ,25(可以省略前导零)
然后您可以用点替换逗号 (
string.replace(',', '.')
) 并用它执行您想要的操作:)This will match zero or more numbers followed by optionally a comma and one or more numbers. e.g:
1,2345; 123; 12,34; ,25 (leading zero may be omitted)
You can then replace the comma with a dot (
string.replace(',', '.')
) and do what you want with it :)搜索
余额 (\d*),(\d*) p\。
替换为
double \$1.\$2
这适用于 IntelliJ IDEA
Search for
Balance (\d*),(\d*) p\.
Replace with
double \$1.\$2
This works in IntelliJ IDEA