How do I create a regular expression for this in android?

android, java, regex

Solution

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);
}

Problem

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.

Original source