Useful regular expressions in Eclipse

Eclipse understands Java, and Javascript, so searching for things such as function usage or definitions is quite easy. Unfortunately, when you throw in some JSP, and some unwieldy code, there are some things that are slightly harder to find. In particular, two bugbears are:

  • Dangling commas, that cause IE to break
  • Stray instances of console.log, used in debugging that cause IE to break

The easiest way to find these is often with a regular expression. For the first, here is a reasonable regex:

,\s*(]|})

For the second, here is another regex (thanks to http://stackoverflow.com/questions/5374843/regex-to-find-an-uncommented-println):

(?m)^((?!//|/\*).)*console\.log.*

Both are quite naive – they give some false positives. But it’s a start. If anyone wants to suggest anything better, please use the boxes below.