views:

25

answers:

2

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?

A: 

I guess I don't know where this pattern is applied at, but if you have ^ and $, would that matches the entire string, including "private String"?

How about this for just the field?

[a-z]{1}.*[^_]{1}

Or, for the entire field statement:-

[\w\s]+[a-z]{1}.*[^_]{1}
limc
Why are you using `{1}`?
Peter Boughton
+1  A: 

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
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
You need to explicitly check "case sensitive" in the SSR.
Stefan Kendall
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
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
If you found bugs, please submit them at http://youtrack.jetbrains.net/issues/IDEA, otherwise they will not be fixed in IDEA 10.
CrazyCoder