-3

What is the regex using javax.validation.constraints @Pattern for user not to be able to choose username such as "admin" or "manager"?

I am not understanding how to use "?!" to indicate word which must be excluded. Could you please suggest some examples with exclusion of just "admin" string and I will figure out the rest.

Aubergine
  • 5,862
  • 19
  • 66
  • 110
  • Okay, everything except the first paragraph of this question is just a rant. -1, and closevote, until you make this an actual question. – tckmn Sep 01 '13 at 21:57
  • 2
    I'm not helping when your "question" is just a rant. – tckmn Sep 01 '13 at 22:01
  • You're not going to get very much help if your "question" includes a rant about being sad if we mark it as a duplicate. – synth3tk Sep 01 '13 at 22:03
  • 1
    If you don't edit your question into something sensible, nobody will help you. We're not going to "answer" a non-question. This is not the place to rant about things you don't like. – tckmn Sep 01 '13 at 22:09
  • Better, but you still need to show at least a little research effort. – tckmn Sep 01 '13 at 22:12

1 Answers1

1

You can use the following expression which will match any value that is not manager or admin:

^(?!(admin|manager)).*$

and if you want to disallow the user to choose usernames which contain manager or admin anywhere in the string like usr_admin, myManager_101, etc ..

Then you can use the following:

^(?!.*?(admin|manager)).*$
Ibrahim Najjar
  • 19,178
  • 4
  • 69
  • 95
  • absolutely great, simple to understand, saved for history and future use. Could not crack the other questions. Thanks! – Aubergine Sep 01 '13 at 22:24
  • @Aubergine You are welcome. I voted to close your question at first but then you made your self more clear. Anyway, don't forget to make the expression case-incentive so that it works for `manager`, `MaNager`, `AdMiN`, etc.. – Ibrahim Najjar Sep 01 '13 at 22:26
  • I think you forgot to anchor the lookahead in your first regex. As it is, you're only matching strings that don't *start* with `admin` or `manager`. – Alan Moore Sep 02 '13 at 04:15
  • @AlanMoore Thank you. That is exactly what I want the first expression to do. – Ibrahim Najjar Sep 02 '13 at 12:21