Skip to content Skip to sidebar Skip to footer

How To Extract Content From

Html Tag

I have the following HTML as input:

Hello

How are you?

Hello again
How can I only output 'Hello' from this? (only cont

Solution 1:

You could add an id="yourID" to each element then do a select like so:

Javascript:

let p1 = document.getElementById("element1").value

HTML:

<p id="element1"> </p>

Solution 2:

I think you might be looking for something like this:

Regexr=newRegex("<p>(.*?)<\\/p>");
stringp1= r.Matches(myString)[0].Groups[1].Value;
stringp2= r.Matches(myString)[1].Groups[1].Value;

The output looks like this:

Hello
How are you?

Keep in mind though this isn't the most bombproof method, iterating through the results might be useful to keep in mind going forward:

foreach (Match m in r.Matches(myString))
{
    Console.WriteLine(m.Groups[1].Value);
}

Post a Comment for "How To Extract Content From

Html Tag"