[regex]:: <\w+:element(\s+(?(\w+=)((?![iI][dD]=)\w+=)|\w+=)['"][^=]+?['"])+\s*/>

Pattern: (?(look-forward-condition)if-matches|if-not-matches)

It matches all the elements that have no attribute id contained.
Used mainly in ascx controls. The reason is that .NET runtime automatically adds id attributes and you can not modify their values. It might be something like "ctl0", "ctl10" etc. Therefore you can find for example (after appropriate modifying) elements like <asp:Button CausesValidation="false" Text="click me" runat="server" />
You can easily alter the expression so that it can be used for any element without given attribute.

Meta: 2007-06-04, Pepa

When working on the coloring script, I used regular expressions quite heavily. Until them I rarely had occassion to prove how excellent tool regular expressions are. But then I felt this time they could be useful, so I opened Expresso and started learning again. The "The 30 Minute Regex Tutorial" with Expresso is excellent and surely worth reading.

During the fun I found some of them at least a little bit interesting. Do you know you can match a prefix/sufix (without capturing it)? Or the absence of prefix/suffix? The 30 min tutorial brings this pieces to light. And what about conditional expression? That sounds good, doesn't it. The only thing this tutorial is missing is better explanation of working with stack - balancing group. Never mind, can be found elsewhere..

[regex]:: (?<=\W|^)(?<key>if|else|while)

Pattern: (?<=exp)(?<name>exp)

Matches all if/else/while if their prefix is either start of the line (^) or non-letter/digit character (\W).

zero-width positive lookbehind
  Any non-word character
  ^  (anchor to start of string)
End Capture
Capture to <key>
End Capture
[regex]:: (?(\$null\W|\$false\W|\$true|\$_\W|\$args\W)$^|\$[\w]+)

Pattern: (?(look-forward-condition)if-matches|if-not-matches)

Matches all variables starting with "$" except key words $null/false/true/_/args. First it looks forward if there is something like $null\W or $false\W etc.

  • If so, then matches nonsense string $^ - it means that the whole expression doesn't match the string.
  • If not, then it matches the string starting with "$" and continuing until non-letter/digit character is matched.

Meta: 2007-03-04, Pepa