Skip to content Skip to sidebar Skip to footer

Regular Expression To Find Hidden Fields In Html

I am looking for a regular expression to find all input fields of type hidden in html output. Anyone know an expression to do such?

Solution 1:

I agree that the link Radomir suggest is correct that HTML should not be parsed with regular expressions. However, I do not agree that nothing meaningful can be gleaned from their use together. And the ensuing rant is totally counter-productive.

To correct Robert's RegEx:

<([^<]*)type=('|")hidden('|")>[^<]*(/>|</.+?>)

Solution 2:

I know you asked for regular expression, but download Html Agility Pack and do the following:

var inputs = htmlDoc.DocumentNode.Descendants("input");
foreach (var input in inputs)
{
   if( input.Attributes["type"].Value == "hidden" )
   // do something
}

You can also use xpath with html agility pack.

Solution 3:

Regular expressions are generally the wrong tool for the job when trying to search or manipulate HTML or XML; a parsing library would likely be a much cleaner and easier solution.

That said, if you're just looking through a big file and accuracy isn't critical, you can probably do reasonably well with something like <input[^>]*type="?hidden"?.

Post a Comment for "Regular Expression To Find Hidden Fields In Html"