/* package whatever; // don't place package name! */
import java.util.* ;
import java.lang.* ;
import java.io.* ;
import java.util.ArrayList ;
import java.util.List ;
import java.util.regex.Matcher ;
import java.util.regex.Pattern ;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
{
String s
= "NameJJ,ABC/firstname,120, NameBB,ABC/secondname,100,NameCC,ABC/thirdname,150,NameJJ,ABC/firstname,200,NameBB,ABC/secondname,300,NameCC,ABC/thirdname,500" ;
List< Integer> listNameJJ = getList( "(\\ w+)JJ,(\\ w+)\\ /(\\ w+),(\\ d+)" , s) ;
List< Integer> listNameBB = getList( "(\\ w+)BB,(\\ w+)\\ /(\\ w+),(\\ d+)" , s) ;
List< Integer> listNameCC = getList( "(\\ w+)CC,(\\ w+)\\ /(\\ w+),(\\ d+)" , s) ;
System .
out .
println ( listNameJJ
) ; System .
out .
println ( listNameBB
) ; System .
out .
println ( listNameCC
) ; }
public static List
< Integer
> getList
( String regex,
String str
) { Pattern pattern = Pattern.compile ( regex) ;
Matcher matcher = pattern.matcher ( str) ;
List< Integer> list = new ArrayList<> ( ) ;
while ( matcher.find ( ) ) {
list.
add ( Integer .
valueOf ( matcher.
group ( 4 ) ) ) ; }
return list;
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CmltcG9ydCBqYXZhLnV0aWwuQXJyYXlMaXN0OwppbXBvcnQgamF2YS51dGlsLkxpc3Q7CmltcG9ydCBqYXZhLnV0aWwucmVnZXguTWF0Y2hlcjsKaW1wb3J0IGphdmEudXRpbC5yZWdleC5QYXR0ZXJuOwoKLyogTmFtZSBvZiB0aGUgY2xhc3MgaGFzIHRvIGJlICJNYWluIiBvbmx5IGlmIHRoZSBjbGFzcyBpcyBwdWJsaWMuICovCmNsYXNzIElkZW9uZQp7CglwdWJsaWMgc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