/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class ArrayFinder
{
	public ArrayFinder()
	{
		List<String> inputs = new ArrayList<String>();
		inputs.add("foo");
		inputs.add("bar");
		inputs.add("baz");
		inputs.add("samba");
		inputs.add("batch");
		
		System.out.println( preg_grep("ba.*", inputs) );
	}
	
	public static List<Integer> preg_grep(String pattern, List<String> array) 
	{
		List<Integer> indexes = new ArrayList<Integer>();
		
		int index = 0;
		for (String item : array) {
			if (item.matches("ba.*")) {
				indexes.add(index);
			}
			++index;
		}
		
		return indexes;
	}
	
	public static void main (String[] args) throws java.lang.Exception
	{
		new ArrayFinder();
	}
	
}