Regular Expression to find a string included between two characters while EXCLUDING the delimiters

前端 未结 12 2507
旧时难觅i
旧时难觅i 2020-11-21 23:49

I need to extract from a string a set of characters which are included between two delimiters, without returning the delimiters themselves.

A simple example should b

12条回答
  •  遥遥无期
    2020-11-22 00:31

    Here is how I got without '[' and ']' in C#:

            var text = "This is a test string [more or less]";
            //Getting only string between '[' and ']'
            Regex regex = new Regex(@"\[(.+?)\]");
            var matchGroups = regex.Matches(text);
            for (int i = 0; i < matchGroups.Count; i++)
            {
                Console.WriteLine(matchGroups[i].Groups[1]);
            }
    

    The output is:

    more or less
    

提交回复
热议问题