我想通過正則表達式從字符串中提取歐元金額。Java正則表達式提取歐元金額
目前我只得到5
作爲結果,並不能理解我的錯誤。如何有一個合適的解決方案看起來像在我的字符串中檢測17,05 Euro
或85 EUR
等變體?
String regExp = ".*([0-9]+([\\,\\.]*[0-9]{1,})?) *[Eu][Uu][Rr][Oo]? .*";
Pattern pattern = Pattern.compile(regExp);
String input1 = "aerae aerjakaes jrj kajre kj 112123 aseraer 1.05 Eur aaa";
Matcher matcher = pattern.matcher(input1);
matcher.matches();
System.out.println(matcher.group(1));
結果:
5
檢查[this](https://stackoverflow.com/a/37571199/2064981)。可以幫助你;)在[regex101](https://regex101.com/r/kL8pD9/7)修改。 – ClasG
'。*?'非貪婪且無需轉義',''在'[]' –