0

I want to match all lines where asp:DropDownList does not contain a class selectpicker

Here's what I have so far:

^((\b<asp:DropDownList\b)*(?!selectpicker).)*$

My test strings are:

<asp:DropDownList class="form selectpicker">
<asp:DropDownList class="selectpicker">
<asp:DropDownList class="form">
<asp:TextBox class="selectpicker">
<asp:TextBox class="form">

I only want 3rd item from the list as that is the only DropDownList tag not containing the class.

user869375
  • 2,299
  • 5
  • 27
  • 46

2 Answers2

1

You can use

^<asp:DropDownList(?!.*class="[^"]*selectpicker[^"]*").*>$

It uses negative lookahead to ensure that the quoted string following class does not contain selectpicker. (That said, in most cases, it would be preferable to use an actual XML parser instead)

https://regex101.com/r/ghhAL0/1

CertainPerformance
  • 356,069
  • 52
  • 309
  • 320
1

Here is a solution using a tempered greedy token:

<asp:DropDownList (?:(?!class="[^"]*selectpicker[^"]*").)*>

It matches anything that does not contain the pattern class="[^"]*selectpicker[^"]*".

.NET Regex Demo

wp78de
  • 18,207
  • 7
  • 43
  • 71