7

I'm using AWS Cognito for authenticating my application.As per the AWS Cognito guidelines, a proper username should follow the regular expression as follows [\p{L}\p{M}\p{S}\p{N}\p{P}]+ What does this regular expression mean?

Vignesh S
  • 169
  • 2
  • 10
  • 1
    i upvoted because the specificity of this question is actually useful. AWS Cognito HATES spaces and will throw this error if you submit a username with a trailing space. I suspect that was the problem OP was facing. So for the sake of posterity, to dismiss this error you might need to `trim()` your username payload before dispatching to AWS – JP Lew Jul 08 '18 at 02:17

1 Answers1

10

This expression allows almost any kind of character and must have at least 1 character to be inputted.

If you put this regular expression through regex101.com, it will tell you what each expression is used for.

So for your one:

\p{L} matches any kind of letter from any language.

\p{M} matches a character intended to be combined with another character (e.g. accents, umlauts, enclosing boxes, etc.)

\p{S} matches any math symbols, currency signs, dingbats, box-drawing characters, etc.

\p{N} matches any kind of numeric character in any script.

\p{P} matches any kind of punctuation character.

'+' Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed

Community
  • 1
  • 1
MinistryOfChaps
  • 1,341
  • 15
  • 27
  • 6
    in other words, it can contain pretty much everything except white space characters – JP Lew Jul 08 '18 at 02:19
  • Could you point me to exact point in documentation this is specified? – pubudut Sep 17 '19 at 16:41
  • https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cognito-userpoolidentityprovider.html in ProviderName, you can see the pattern that the String should match, it is a string with no spaces – stamstam May 18 '20 at 17:47