class ThreadUtil {

    static public Thread[] getAllThreadsMatching(final String regex) {
        if (regex == null)
            throw new NullPointerException("Null thread name regex");
        final Thread[] threads = getAllThreads();
        ArrayList<Thread> matchingThreads = new ArrayList<Thread>();
        for (Thread thread : threads) {
            if (thread.getName().matches(regex)) {
                matchingThreads.add(thread);
            }
        }
        return matchingThreads.toArray(new Thread[0]);
    }

}