1

All I try to do doesn't work. I can't combine this two regexes:

^(?!(.)\1+$).{8,40}$ //this doesn't let to create word with only one symbol like '111111111111' or enter code here`fffffffffffff`
^\s|\s$ //this checks if first or last symbol is space

So I need regex that will include first one and opposite of the second one, e.g.: word should be more than 8 symbols, not be containing only one symbol and first and last symbol shouldn't be space.

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Robert
  • 59
  • 2
  • 2
  • 7
  • 2
    You say "all I try" - what do you try? Please explain what you are doing, what sample strings you test your patterns against, what regex engine you are using, so that we could help you. – Wiktor Stribiżew Apr 29 '20 at 17:23
  • I try to combine them one after second, using 'AND' operator like `?=` – Robert Apr 29 '20 at 17:31
  • `?=` is not AND operator. If you mean you are using `(?=....)` , it is a positive lookahead, and it is the right way, but please show the expression in full. – Wiktor Stribiżew Apr 29 '20 at 17:32
  • Yes, sorry I missed full statement. I try this (?!(.)\1+$)^(?!=\s)(?!=\s$).{8,40}$ – Robert Apr 29 '20 at 17:44
  • @WiktorStribiżew thanks! but actually I mean, my word (password) can be more that 8 symbols (works), all symbols not one symbol (works), and first and last symbol can't be space. I check this regex on regex101.com, and it matches to this ' dfdsfsdfgfdfgfdfd '. that's why it is hard to find out solution – Robert Apr 29 '20 at 17:53
  • Sorry, I did not notice the `=` in your lookaheads, they make `=` required before whitespaces, `^(?!(.)\1+$)(?!\s)(?!.*\s$).{8,40}$`, see https://regex101.com/r/neQhQv/1 – Wiktor Stribiżew Apr 29 '20 at 17:57
  • Thank you so much! Could you post this in answer so that I mark it as correct? – Robert Apr 29 '20 at 18:00
  • 1
    I [already posted](https://stackoverflow.com/a/60782571/3832970) and explained, and showed a demo. – Wiktor Stribiżew Apr 29 '20 at 18:08
  • I mean here, in this question. – Robert Apr 29 '20 at 18:23

0 Answers0