In Java there is a function on the Regex Matcher object that allows you to check if a string contains even a prefix of the pattern. This function is called lookingAt.