Added nextMatchingSubstring functionality