-2

I have one regex which allows one Upper case, one Lower case, 8-16 characters and Most special characters including space. I want add allow space in the regex.

I have tried :

  1. Blank spaces in regular expression

  2. Regex to allow alphanumeric, spaces, some special characters

  3. Java space and newline regex for split

My regex is as follow :

(?=^.{8,16}$)(?=.*[\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\>\=\?\@\[\]\{\}\\\\\^\_\`\~\|])(?=.*[a-z])(?=.*[A-Z])(?!.*\s)[0-9a-zA-Z\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\>\=\?\@\[\]\{\}\\\\\^\_\`\~\|]]*$

I just want to add space in this. I have tried \s and [ ]? but nothing works.

I have checked the regex on https://regex101.com/

Any suggestions would be appreciated.

VLAZ
  • 26,331
  • 9
  • 49
  • 67
Annie
  • 2,397
  • 3
  • 18
  • 26
  • https://stackoverflow.com/questions/15472764/regular-expression-to-allow-spaces-between-words – Goku Dec 06 '18 at 11:51
  • @Goku nothing is working for me i have added this type of space and checked on given site.. but not working – Annie Dec 06 '18 at 11:55
  • have u tried this https://stackoverflow.com/a/21102944/8112541 – Goku Dec 06 '18 at 11:59
  • @Goku not working (?=^.{8,16}$)(?=.*[\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\>\=\?\@\[\]\{\}\\\\\^\_\`\~\|])([\w ]+)(?=.*[a-z])(?=.*[A-Z])(?!.*\s)[0-9a-zA-Z\w\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\>\=\?\@\[\]\{\}\\\\\^\_\`\~\|]*$ – Annie Dec 06 '18 at 12:02
  • Hi @Annie I think your problem is "(?!.*\s)" which translates to "no whitespaces" and includes spaces. But I cannot say for sure because I still don't get exactly what you try to accomplish and don't have a test string that works. Just one tip: you can save your regex incl. example input at regex101.com and share it via link. – Johannes Stadler Dec 06 '18 at 13:01
  • @Johannes she wants a password with one upper case, one lower case, one special character with space.. i.e. "Annie123 " or "Annie222!" these wil be valid one.. there have to b one special character and that character can be white space – Vidhi Dave Dec 06 '18 at 16:59
  • @JohannesStadler thanks that worked for me.. please post as an answer for future visitors.. i will accept – Annie Dec 20 '18 at 04:47

1 Answers1

2

Probably there will be mistake in grouping.

As far as I have used RegEx, [ ] or \s will support the single space

Tej
  • 195
  • 7
  • Yes I will test and I will try to get it fixed, But if you send me a test string based on what you are testing, then that would be easier for me to analyze. – Tej Dec 07 '18 at 05:55