Matching a pattern in many lines of text This is the relevant piece of my code (false is returned if the whole cycle is finished, pattern is a String passed to the function):

for (FileLine fileLine : fileLines) {
    itemText = fileLine.getText();

    itemStrings = new ArrayList&lt;String&gt;();
    itemStrings.addAll(Arrays.asList((itemText).split(" ")));
    for (String itemString : itemStrings) {
        if (itemString.equalsIgnoreCase(pattern)) {
            return true;
        }
    }
}


How can I speed this up? I've tried using regex, something like:

//before the for cycle
Pattern regexPattern = Pattern.compile(pattern);

//in the cycle
if (regexPattern.matcher(itemText).matches())
    return true;


But it doesn't work for some reason. Maybe I'm doing it wrong, or there's a completely different way of accomplishing this?
You should probably be using find() instead of matches() (source).

I would recommend using regexpal to test out your pattern, just in case.

Whether or not the Regex solution is faster, you'd have to run some tests, but I suspect it's MUCH faster.