fork(2) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.regex.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. // your code goes here
  14. String regString = "04/30/13 INCOME REINVEST 0.0245 $24.66 $12.34 1.998 1,008.36";
  15. String regex="([0-9]{2}/[0-9]{2}/[0-9]{2})\\s*([\\w ]+)\\s*(\\d+(\\.\\d+)?)\\s*\\$(\\d+(\\.\\d+)?)\\s*\\$(\\d+(\\.\\d+)?)\\s*(\\d+(\\.\\d+)?)\\s*(\\d+(,\\d{3})*(\\.\\d+)?)";
  16. Pattern match = Pattern.compile(regex);
  17.  
  18. Matcher m = match.matcher(regString);
  19. while (m.find()) {
  20. System.out.println(m.group(1)); //04/30/13
  21. System.out.println(m.group(2)); //INCOME REINVEST
  22. System.out.println(m.group(3)); //0.0245
  23. System.out.println(m.group(5)); //24.66
  24. System.out.println(m.group(7)); //12.34
  25. System.out.println(m.group(9)); //1.998
  26. System.out.println(m.group(11)); //1,008.86
  27. }
  28. }
  29. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
04/30/13
INCOME REINVEST 
0.0245
24.66
12.34
1.998
1,008.36