2

The background is that I have a complicated memory issue in Delphi. But a theory is that an enum of 5 values can be the root of the bug. So my question to you is:

How do I write a regexpression to search sourcefiles for an enum with 5 values ? An enum in Delphi looks like this

myEnum = (value1,value2,value3,value4,value5);

There can of course be any combination of spaces, tabs and newlines between the values.

berocoder
  • 197
  • You'll probably want to ask this on StackOverflow, and it will likely be moved there shortly. – Joe Internet Feb 03 '10 at 11:19
  • I was not sure what forum was best. But my thought was that regexpressions is not for programmers only. It is handy to search all kinds of text. In this case it happens to be a source file for Delphi. But if the question was moved it is ok for me :) – berocoder Feb 03 '10 at 12:23

1 Answers1

1

this should give you all the lines you are searching for in your files:

perl -n -e 'if ($_ =~ m/\W*\w+\W*=\W*\(\W*\w+\W*,\W*\w+\W*,\W*\w+\W*,\W*\w+\W*,\W*\w+\W*\)\W*;/) { print $_; }'

just parse all you delphi source files through this perl one liner.
some more explanations:

  • \W => means non-word character
  • \w => means alphanumerical character including underscore
  • + => at least one occurrence
  • * => zero or more occurrence
  • $_ => current line of which will be filled by -n

hope this helps.

Christian
  • 4,723