regex time complexity

Hey i want to know which is faster using regex or for loop for lets say diving a string by space and counting the length
for eg:

String[] words=messages[i].split("\\s");
int length=words.length;

and if we do this like:

int getwordCount(String message)
{
        int result = 1;
        for (char ch : message.toCharArray())
		{
            if (ch == ' ') 
				++result;
        }
        return result; 
}

which of these two code will take more time?

Comments (0)