1

I have 2 input tag like below

<input name="daily" value="Next" title="Next"
class="btn btn-link" type="submit"/>

<input type="submit" name="daily" value="Next" title="Next"
 class="btn btn-link"/>

I am using

<input[^>]*\s*type\s*=\s*('|"|)Submit\s*(\1)[^>]*\s*value\s*=('|"|)Next\s*(\3)[^>]*>

But only one is match as per above regex.

I want the regex which match ignoring the position of type or value attribute.

user3138879
  • 183
  • 2
  • 9
  • 3
    Base rule: do not use regex for parsing html. Use `HtmlAgilityPack`. –  Oct 14 '14 at 06:27
  • Your regex is tailor made for the second input.A lot would be needed to change to make it accept first one.Guess its better you make a new one. – vks Oct 14 '14 at 06:28
  • but I want to use regex any how. – user3138879 Oct 14 '14 at 06:29
  • Never ever use regex to parse html. Read this http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags :) – Alex Oct 14 '14 at 06:56

2 Answers2

5
<input[^>]*\s*(?=[^>]*type\s*=\s*('|"|)Submit\s*(\1))[^>]*\s*(?:value\s*=('|"|)Next\s*(\3))[^>]*>

Try this.Have added a lookahead which will make sure type attreibute is there somewhere in the string not just before value See demo.

http://regex101.com/r/yA5iD9/1

vks
  • 67,027
  • 10
  • 91
  • 124
0

Why you dont use the ? operator?

<input\s*(type="\w+"\s*)?name="\w+"\s*value="\w+"\s*title="\w+"

Or in your case use this:

<input (type="submit" )?name="daily" value="Next" title="Next"
Mehdi Khademloo
  • 2,754
  • 2
  • 20
  • 40