fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.*;
  5.  
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. String [] arr = {"${US.IDX_CA}", "${UK.IDX_IO}", "${NZ.IDX_BO}", "${JP.IDX_TK}", "${US.IDX_MT}", "more-elements-with-completely-different-patterns-which-is-irrelevant"};
  11. Pattern pattern = Pattern.compile("\\bIDX_(\\w{2})\\b");
  12. for (String s : arr){
  13. Matcher m = pattern.matcher(s);
  14. while (m.find()){
  15. System.out.println(m.group(0)); // Get the whole match
  16. System.out.println(m.group(1)); // Get the 2 chars after IDX_
  17. }
  18. }
  19. }
  20. }
Success #stdin #stdout 0.04s 2184192KB
stdin
Standard input is empty
stdout
IDX_CA
CA
IDX_IO
IO
IDX_BO
BO
IDX_TK
TK
IDX_MT
MT