I’ve a string which is in the below format.
‘abc’,’def’,’ghi’ etc
I want to find the number of words in this string (words inside single quotes) using regex.
edit:
tried this, I think this works:
int c = 0;
Pattern pattern = Pattern.compile("'[^*]'");
Matcher matcher = pattern.matcher(myString);
while(matcher.find()){
c++;
}
Why would you use a regexp to count ?
You could use a str.split(“,”) and get the array size ?