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.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

How do I collapse sections of code in Visual Studio Code for Windows?

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ