Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- String currencyValues = "45,890.00,12,345.00,23,765.34,56,908.50";
- String regEx = "\.[0-9]{2}[,]";
- String[] results = currencyValues.split(regEx);
- //System.out.println(Arrays.toString(results));
- for(String res : results) {
- System.out.println(res);
- }
- }
- 45,890 //removing the decimals as the reg ex is exclusive
- 12,345
- 23,765
- 56,908.50
- String regEx = "(?<=\.[0-9]{2}),";
- public static void main(String[] args) {
- String currencyValues = "45,890.00,12,345.00,23,765.34,56,908.50";
- String regEx = "(?<=\.[0-9]{2}),"; // Using the regex with the look-behind
- String[] results = currencyValues.split(regEx);
- for (String res : results) {
- System.out.println(res);
- }
- }
- 45,890.00
- 12,345.00
- 23,765.34
- 56,908.50
- String currencyValues = "45,890.00,12,345.00,23,765.34,56,908.50,55.00,345,432.00";
- Pattern pattern = Pattern.compile("(\d{1,3},)?\d{1,3}\.\d{2}");
- Matcher m = pattern.matcher(currencyValues);
- while (m.find()) {
- System.out.println(m.group());
- }
- 45,890.00
- 12,345.00
- 23,765.34
- 56,908.50
- 55.00
- 345,432.00
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement