I need to check line of string using Regex.
I can verify line content but I am not able to check if line length is some exact number.
Here is the example :-
system WAS SP2 NA5 na10-xyz cpu,core-2,idle 1360294220 0
For above line, I need to see if there are 8 string separated by single white space.
I have designed regex for checking above string.
\w+(\s\w+){3}(\s(\w|\W)+){2}\s\d{10}\s\d+
so what do I need to add to check string length?
Here is what I have looked so far.
Regex Java Total String Length
Regex to match words of a certain length
EDIT :-
I don't want to use split(" ")
function as i will be checking more than 1 million line with regex . So if i can merger length checking with regex , it would be better in my opinion.
EDIT 2 :-
With my current regex expression , if there are more than 8 elements it will not throw error. like this example :-
system WAS aa aa SP2 NA5 na10-xyz cpu,core-2,idle 1360294220 0
here aa aa
are extra strings which i added and it doesn't throw error with current regex expression.