Suppose I have a string like this:
string = "Manoj Kumar Kashyap";
Now I want to create a regular expression to match where Ka appears after space and also want to get index of matching characters.
I am using java language.
Suppose I have a string like this:
string = "Manoj Kumar Kashyap";
Now I want to create a regular expression to match where Ka appears after space and also want to get index of matching characters.
I am using java language.
You can use regular expressions just like in Java SE:
Pattern pattern = Pattern.compile(".* (Ka).*");
Matcher matcher = pattern.matcher("Manoj Kumar Kashyap");
if(matcher.matches())
{
int idx = matcher.start(1);
}
If you really need regular expressions and not just indexOf
, it's possible to do it like this
String[] split = "Manoj Kumar Kashyap".split("\\sKa");
if (split.length > 0)
{
// there was at least one match
int startIndex = split[0].length() + 1;
}