我想在字符串(传入的短信)中找到价格值。 我正在使用java正则表达式:
Pattern pattern = Pattern.compile("\\d+.\\d\\d");/
但是这个表达式也找到了日期。 例如12.12.2013返回12.12 。 如果有某种方法只能找到价格值? 也许不使用正则表达式,因为字符串不长。
编辑消息示例:
Oplata tovariv:S1LV0GRU RYKAVUCHKA 510,UA 02.04.2013 21:12 kartka 1111111111 na sumu 24.72UAH 。 Dostupnyi zalyshok 1351.58UAH。
I want to find price value in string(incoming sms message). I am using java regex:
Pattern pattern = Pattern.compile("\\d+.\\d\\d");/
But this expression find the date too. For example 12.12.2013 returns 12.12. If there some way to find only price value? Maybe not using regex, because string isn't long.
EDITED Example of message:
Oplata tovariv: S1LV0GRU RYKAVUCHKA 510, UA 02.04.2013 21:12 kartka 1111111111 na sumu 24.72UAH. Dostupnyi zalyshok 1351.58UAH.
最满意答案
如果您的价格的一般格式是xxxx.xx,您可以使用:
"(?<!(?:\\d|\\.))\\d+\\.\\d{2}(?!\\.)"至少它与日期不匹配。 (不要忘记逃避这一点,因此它不是通配符)
If the general format of your prices is xxxx.xx, you can use:
"(?<!(?:\\d|\\.))\\d+\\.\\d{2}(?!\\.)"At least it wouldn't match dates. (Don't forget to escape the point so it's not a wildcard)
java查找字符串中的价格值[关闭](java find price value in string [closed])我想在字符串(传入的短信)中找到价格值。 我正在使用java正则表达式:
Pattern pattern = Pattern.compile("\\d+.\\d\\d");/
但是这个表达式也找到了日期。 例如12.12.2013返回12.12 。 如果有某种方法只能找到价格值? 也许不使用正则表达式,因为字符串不长。
编辑消息示例:
Oplata tovariv:S1LV0GRU RYKAVUCHKA 510,UA 02.04.2013 21:12 kartka 1111111111 na sumu 24.72UAH 。 Dostupnyi zalyshok 1351.58UAH。
I want to find price value in string(incoming sms message). I am using java regex:
Pattern pattern = Pattern.compile("\\d+.\\d\\d");/
But this expression find the date too. For example 12.12.2013 returns 12.12. If there some way to find only price value? Maybe not using regex, because string isn't long.
EDITED Example of message:
Oplata tovariv: S1LV0GRU RYKAVUCHKA 510, UA 02.04.2013 21:12 kartka 1111111111 na sumu 24.72UAH. Dostupnyi zalyshok 1351.58UAH.
最满意答案
如果您的价格的一般格式是xxxx.xx,您可以使用:
"(?<!(?:\\d|\\.))\\d+\\.\\d{2}(?!\\.)"至少它与日期不匹配。 (不要忘记逃避这一点,因此它不是通配符)
If the general format of your prices is xxxx.xx, you can use:
"(?<!(?:\\d|\\.))\\d+\\.\\d{2}(?!\\.)"At least it wouldn't match dates. (Don't forget to escape the point so it's not a wildcard)
发布评论