fork(4) 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. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. String str = "#min({(((fields['example6'].value + fields['example5'].value) * ((fields['example1'].value*5)+fields['example2'].value+fields['example3'].value-fields['example4'].value)) * 0.15),15,9.087})";
  13. ArrayList<String> arL = new ArrayList<String>();
  14. String rx = "(?<=fields\\[['\"])[\\w\\s]*(?=['\"]\\])";
  15. Pattern ptrn = Pattern.compile(rx);
  16. Matcher m = ptrn.matcher(str);
  17. while (m.find()) {
  18. arL.add(m.group());
  19. }
  20. // Demo
  21. String[] arr = new String[arL.size()];
  22. arr = arL.toArray(arr);
  23. System.out.println(Arrays.toString(arr));
  24. }
  25. }
Success #stdin #stdout 0.1s 320320KB
stdin
Standard input is empty
stdout
[example6, example5, example1, example2, example3, example4]