Regex filter & quot; with & lt; & gt; tags included

I am having problems with some Regex code that might help.

I have the following row of data:

abcd " something code " nothing  "f <b> cannot find this section </b> "

I want to find sections between quotation marks ".

I can get it if it works fine using the following regax:

foreach (Match match in Regex.Matches(sourceLine, @""((\\")|[^"(\\")])+""))

However, if the section between quotation marks contains <>, it does not find the section. Not sure what to do to include tags <>in the regex.

Thank you for your time.

+3
source share
3 answers

A […] , [^…] . , [^"(\\")] , &, q, u, o, t, ;, (, \ ). , "(").

:

"(.*?)"

*? *, .

0
public List<string> Parse(string input)
{
    List<string> results = new List<string>();
    bool startSection = true;
    int startIndex = 0;
    foreach (Match m in Regex.Matches(input, @"(^|[^\\])(&quot;)"))
    {
        if (startSection)
        {
            startSection = false;
            // capture a new section
            startIndex = m.Index + "&quot;".Length;

        }
        else
        {
            // next match starts a new section to capture
            startSection = true;
            results.Add(input.Substring(startIndex, m.Index - startIndex + 1));
        }
    }
    return results;
}
+1

HttpUtility.HtmlDecode . .

0
source

Source: https://habr.com/ru/post/1766730/


All Articles