Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. public static void main(String[] args) {
  2. String currencyValues = "45,890.00,12,345.00,23,765.34,56,908.50";
  3. String regEx = "\.[0-9]{2}[,]";
  4. String[] results = currencyValues.split(regEx);
  5. //System.out.println(Arrays.toString(results));
  6. for(String res : results) {
  7. System.out.println(res);
  8. }
  9. }
  10.  
  11. 45,890 //removing the decimals as the reg ex is exclusive
  12. 12,345
  13. 23,765
  14. 56,908.50
  15.  
  16. String regEx = "(?<=\.[0-9]{2}),";
  17.  
  18. public static void main(String[] args) {
  19. String currencyValues = "45,890.00,12,345.00,23,765.34,56,908.50";
  20. String regEx = "(?<=\.[0-9]{2}),"; // Using the regex with the look-behind
  21. String[] results = currencyValues.split(regEx);
  22. for (String res : results) {
  23. System.out.println(res);
  24. }
  25. }
  26.  
  27. 45,890.00
  28. 12,345.00
  29. 23,765.34
  30. 56,908.50
  31.  
  32. String currencyValues = "45,890.00,12,345.00,23,765.34,56,908.50,55.00,345,432.00";
  33. Pattern pattern = Pattern.compile("(\d{1,3},)?\d{1,3}\.\d{2}");
  34. Matcher m = pattern.matcher(currencyValues);
  35. while (m.find()) {
  36. System.out.println(m.group());
  37. }
  38.  
  39. 45,890.00
  40. 12,345.00
  41. 23,765.34
  42. 56,908.50
  43. 55.00
  44. 345,432.00
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement