Hello there,

I'm a newbie in regex in c#, and I have a problem in parsing the html tag using regex in the <span> tag.
here the html file that i want to get the value.



<li><span>Date of birth</span>December 16, 2000 (Age: 12)</li>

i want to get the  December 16, 2000 (Age: 12)

any sugggestion will accepted,thanks in advanced.

But I guess you would like to get all whats inside li tags, so all within <li>...</li>? Am I correct?
If so, this is the pattern and the code you can use:

            string pattern = @"<li>(.*?)</li>";
            Regex regex = new Regex(pattern);
            //1. if one occurence in a string:
            Match match = regex.Match(text);
            if (match.Success)
            {
                string myText = match.Groups[1].Value;

                string[] twoData = myText.Split(',');
                foreach (string data in twoData)
                {
                    myText = data;
                }
            }

thanks mitja

i have already a patter, but my problem is the span tag also return instead of

December 16, 2000 (Age: 12)

Here is my code

 Match reg = Regex.Match(html, @"<li>(.+?)</li>").NextMatch();
        if (reg.Success)
        {
            string myText = reg.Groups[1].Value;
            string[] twoData = myText.Split(',');
            foreach (string data in twoData)
            {
                myText = data;
            }
        }

   The problem is it returns 

<span>Date of birth</span>December 16, 2000 (Age: 12)

i want only get the December 16, 2000 (Age: 12)

You can use Remove method of String class with a help of a tag (your span tag of html):

            string pattern1 = @"<li>(.*?)</li>";
            string tag = "</span>";

            Regex regex = new Regex(pattern1);
            Match match = regex.Match(text);
            string myText = match.Groups[1].Value;            
            myText = myText.Remove(0, myText.IndexOf(tag) + tag.Length);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.