Regex positive match and a negative match in a line
Regex positive match and a negative match in a line
I want to match all lines where asp:DropDownList does not contain a class selectpicker
Here's what I have so far:
^((b<asp:DropDownListb)*(?!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.
2 Answers
2
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)
class
selectpicker
https://regex101.com/r/ghhAL0/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[^"]*".
class="[^"]*selectpicker[^"]*"
.NET Regex Demo
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.