We Recommend

Mastering Regular Expressions Mastering Regular Expressions
As this book shows, a command of regular expressions is an invaluable skill. Regular expressions allow you to code complex and subtle text processing that you never imagined could be automated. Regular expressions can save you time and aggravation. They can be used to craft elegant solutions to a wide range of problems. Once you've mastered regular expressions, they'll become an invaluable part of your toolkit. You will wonder how you ever got by without them.


Posted By

rengber on 01/22/07


Tagged

csharp RegularExpression SourceCodeAnalysis


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

copyleft


Regular Expression to Grab an Object Type Name from a C# Code File.


Published in: Regular Expression 


URL: http://docs.python.org/lib/re-syntax.html

The first part enclosed in parens is a lookbehind matching the word "new" followed by a space. Next is a block matching any non white space characters bordered by zero or more spaces. Last is a lookahead block matching zero or more square brackets or parens. This excludes things like arrays and constructor parameters from the return. (for example, "new string[5]" will just return "string".


  1. (?<=new\s)\s*\S*?\s*(?=[\[\(])

Report this snippet 

You need to login to post a comment.