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

前端 未结 3 1844
野的像风
野的像风 2020-12-17 22:26

Suppose I have a string like this:

string = \"Manoj Kumar Kashyap\";

Now I want to create a regular expression to match where Ka appears af

3条回答
  •  情歌与酒
    2020-12-17 22:46

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

提交回复
热议问题