Showing posts with label regex. Show all posts
Showing posts with label regex. Show all posts

Friday, May 18, 2012

Regex for TSQL comments

This regular expression will help you to match comments in TSQL code.
Single line comments (--)  and multiline (/**/) are supported. Multiline comments can be nested one into another. Only one level of nesting is supported.
/\*(?>(?:(?!\*/|/\*).)*)(?>(?:/\*(?>(?:(?!\*/|/\*).)*)\*/(?>(?:(?!\*/|/\*).)*))*).*?\*/|--.*?\r?[\n]|--.*?$
We used this regular expression to remove all comments from TSQL before analysis.

Inspired by http://stackoverflow.com/a/7690874/1012986

Wednesday, May 2, 2012

How to find unused controls registration in ASP.NET

In order to find unused controls registration this regular expression might be helpfull

<%@\s*Register\s+TagPrefix\s*=\s*"(?<tagprefix>[^"]+)"\s+TagName\s*=\s*"(?<tagname>[^"]+)"\s+Src\s*=\s*"[^"]+"\s*%>(?!.*?\k<tagprefix>:\k<tagname>\s+)

I used powergrep to run this regex. The "Dot matches newline" checkbox should be enabled to work properly.