-1

I have read this article: Regex to find input value attribute

and modified that regex string to:

string regexStr = "(?<1><\s*input\s+[^>]*)(?:(?<2>\sname\s*=\s*)(?<3>\w*find_me\w*)(?<4>[^>\s]*)(?<5>\3))(?<6>[^>]*>)";
var r = new Regex(regexStr, RegexOptions.IgnoreCase | RegexOptions.Singleline);

I'm trying to find this:

<INPUT TYPE="hidden" NAME="FIND_ME" VALUE="">

The above mentioned Regex doesn't find anything.

If i change this: \wfind_me\w to "" then it finds all inputs.

What is wrong?

1) I need to find INPUT & NAME = "FIND ME" 2) I don't know if any additional params will be there ( they may or may not ), the main is INPUT & NAME = "FIND ME".

Community
  • 1
  • 1
Developer
  • 4,158
  • 5
  • 34
  • 66
  • 2
    I'm sure you're aware, but using regular expressions to parse HTML is a bad idea. https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags – Joe Aug 14 '15 at 11:00
  • 2
    You will need to find a framework for the language of your choice which allows you to parse HTMl text. – npinti Aug 14 '15 at 11:01
  • As npinti points out, HTML is not a regular language and thus not good to parse with regexes. – m0skit0 Aug 14 '15 at 11:05
  • 1
    As for the regex, you should have at least useda verbatim string literal. As for a solution: use HtmlAgilityPack, and search for an `input` tag that has `name attribute having `FIND_ME` in it. I guess this what you need. – Wiktor Stribiżew Aug 14 '15 at 12:11

1 Answers1

0

Did it this way:

(?<1><\s*input\s+[^>]*)(?:(?<2>\s*type\s*=\s*)(?<3>[""'])(?<4>[^>\s]*)(?<5>\3))(?:(?<6>\sname\s*=\s*)(?<7>[""'])(?<8>find_me)(?<9>[^>\s]*)(?<10>\3))(?<11>[^>]*>)
Developer
  • 4,158
  • 5
  • 34
  • 66