tags:

views:

249

answers:

5

Currently I am using this one ( edit: I missed to explain that I use this one for excluding exactly these words :p ):

   String REGEXP = "^[^(REG_)?].*";

but matches (exluding) also ERG, EGR, GRE, etc... above

P.S. I removed super because it is another keyword that I must filter, figure an array list composed with more of the following three words to be used as model:

REG_info1, info2, SUPER_info3, etc...

I need three filter matching one model at time, my question focus only on the second filter parsing keywords based on model "info2".

+12  A: 

Just type it literally:

REG

This will only match REG.

So:

String REGEXP = "^(REG_|SUPER_)?.*";


Edit   After you clarified that you want to match every word that does not begin with REG_ or SUPER_, you could try this:

\b(?!REG_|SUPER_)\w+

The \b is a word boundary and the expression (?!expr) is a look-ahead assertion.

Gumbo
Thank you, I remembered something about !, but I was not able to use it because initially I did use it in the wrong manner, now I learned that it is part of "look ahead" assertion :-)
Steel Plume
Great Gumbo! now all wotks perfectly
Steel Plume
A: 

The [] indicate character classes. This is not what you want. You can just use "REG" to match REG. (You can use REG|SUPER for REG or SUPER)

Peter Smit
A: 

How about

\mREG\M

// \mREG\M
// 
// Options: ^ and $ match at line breaks
// 
// Assert position at the beginning of a word «\m»
// Match the characters “REG” literally «REG»
// Assert position at the end of a word «\M»
Lieven
+2  A: 

As everyone have already replied, if you want to match a line starting with REG, you use the regexp "^REG", if you want to match any line that starts REG or SUPER, you use "^(REG|SUPER)" and regular expression negation is, in general, a tricky problem.

To match all lines NOT starting with 'REG' you need to match "^[^R]|R[^E]|RE[^G]" and a regular expression to match all lines not starting with REG or SUPER can be constructed in a similar fashion (start by grouping the "not REG" in parentheses, then construct the "not SUPER" patterns as "[^S]|S[^U]|[SU[^P]...", group this and use alternation for both groups).

Vatine
You have to group the character description: `^([^R]|R[^E]|RE[^G])`. Otherwise the anchor `^` is only refered to the `[^R]`.
Gumbo
You hit the my scope, others have misunderstood my first sentence saying I need a perfect matching, but I need an exact match during an excluding match
Steel Plume
Ohyeah GUMBO!! it works!
Steel Plume
A: 
REGEXP = "^(REG_|SUPER_)"

would match anything that haves REG_ or SUPER_ at the beginning of a string. You don't need more after the group "(..|..)"

pduersteler