I'm writing a program with the below requirement.
I've a string as (Ravi) has good knowledge in (Java)
and from this string I need to get the index values of (
and )
.
I know how to get the first (
using indexOf()
and the last )
, getLastIndexOf()
, but how can I get index values of (
and )
in (Ravi)
and (Java)
I'm able to get the values using
List<String> matchList = new ArrayList<String>();
Pattern regex = Pattern.compile("\\((.*?)\\)");
Matcher regexMatcher = regex.matcher(line);
while (regexMatcher.find()) {
matchList.add(regexMatcher.group(1));
}
for (String str : matchList) {
utterancesSet.add(str);
}
System.out.println(utterancesSet);
But here, I need the index values, not the strings
Thanks