Is there a function that returns index where RegEx match starts?

后端 未结 6 416
栀梦
栀梦 2020-12-29 02:10

I have strings of 15 characters long. I am performing some pattern matching on it with a regular expression. I want to know the position of the substring where the IsM

6条回答
  •  醉梦人生
    2020-12-29 02:47

    For multiple matches you can use code similar to this:

    Regex rx = new Regex("as");
    foreach (Match match in rx.Matches("as as as as"))
    {
        int i = match.Index;
    }
    

提交回复
热议问题