Looking for a regular expression to identify hard coded magic numbers in source code

A frequent issue in code reviews is whether a numeric value should be hard-coded in the code or not. Does anyone know of a nice regular expression that can catch 'magic numbers' in code like:

int overDue = 30;
Money fee = new Money(5.25D);

without also getting a ton of false positives like for loop initialization code?

for (int i = 0; i < array.length; i++) {

}

Answers


A better question would be about asking what tools do that. And the answer would be:

  • Checkstyle
  • FxCop

And many more static code analysis tools.


Need Your Help

Django/Dajax process not being processed

jquery ajax django

Well, I have one form, similar to dajax "django forms" example, all is working fine except the returning JSON is not being processed, I've modified the jquery.dajax.core.js like this:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.