1

I need to match variables that start with a lowercase letter and don't end in an underscore.

I have these three fields:

private String shouldFlag;
private String shouldntFlag_;
private String SHOULDNTFLAG;

With this pattern inverted: ^[a-z].*_$

Used with for fieldname in the following template:

class $Class$ { 
  $FieldType$ $FieldName$ = $Init$;
}

The problem is that SHOULDNTFLAG is still flagged. I tried using ^[a-z].*_$|^[A-Z].*$, but that did not match anything, let alone just shouldFlag. What am I doing wrong here?

Bas Leijdekkers
  • 23,709
  • 4
  • 70
  • 68
Stefan Kendall
  • 66,414
  • 68
  • 253
  • 406

1 Answers1

2

Assuming your variable names can only contain ASCII letters and digits plus the underscore, I would go with

\b[a-z]\w*\b(?<!_)

EDIT: ...and, as @Stefan pointed out, you need to select the "case-sensitive" option.

Alan Moore
  • 73,866
  • 12
  • 100
  • 156
  • This seems to accept SHOULDNTFLAG in Intelli-J. It looks like it's treating the [a-z] character class as [a-zA-Z] – Stefan Kendall Aug 09 '10 at 14:56
  • You need to explicitly check "case sensitive" in the SSR. – Stefan Kendall Aug 09 '10 at 14:58
  • Cool, thanks. I've never actually used that feature. I always expect regex-powered search tools--especially in IDE's and programmers' editors--to be case-sensitive by default, but they keep surprising me. :/ – Alan Moore Aug 09 '10 at 16:20
  • I think Intelli-J's SSR is just a bit broken. I've encountered a number of issues already, and it turns out I can't even use this due to its unpredictable behavior. Hopefully IntelliJ 10 will hammer out these bugs. – Stefan Kendall Aug 09 '10 at 18:34
  • If you found bugs, please submit them at http://youtrack.jetbrains.net/issues/IDEA, otherwise they will not be fixed in IDEA 10. – CrazyCoder Aug 09 '10 at 19:53