fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. import java.util.regex.Matcher;
  6. import java.util.regex.Pattern;
  7.  
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. String lines =
  13. "[no=1, position=batter, name=lee, birth=1900-**-11, age=36, " +
  14. "height=175.0, batcount=3, hit=3, hitAvg=3.0]\n" +
  15. "[no=2, position=pitcher, name=cho, birth=1955-**-14, age=27, " +
  16. "height=180.2, win=4, lose=4, defense=4.0]\n" +
  17. "[no=3, position=batter, name=kim, birth=1999-**-14, age=20, " +
  18. "height=155.0, batcount=2, hit=3, hitAvg=7.0]\n";
  19.  
  20. Matcher m = Pattern.compile( "(\\w+)=(\\S*)[,\\]]" ).matcher( lines );
  21.  
  22. while( m.find() )
  23. {
  24. if( m.group( 1 ).equals( "no" ) )
  25. System.out.println( "" );
  26. System.out.println( m.group( 1 ) + " : " + m.group( 2 ) );
  27. }
  28. }
  29. }
  30.  
Success #stdin #stdout 0.04s 711168KB
stdin
Standard input is empty
stdout
no : 1
position : batter
name : lee
birth : 1900-**-11
age : 36
height : 175.0
batcount : 3
hit : 3
hitAvg : 3.0

no : 2
position : pitcher
name : cho
birth : 1955-**-14
age : 27
height : 180.2
win : 4
lose : 4
defense : 4.0

no : 3
position : batter
name : kim
birth : 1999-**-14
age : 20
height : 155.0
batcount : 2
hit : 3
hitAvg : 7.0