What do comma separated numbers in curly braces at the end of a regex mean?

后端 未结 6 1676
北恋
北恋 2020-11-28 12:36

I am trying to understand the following regex, I understand the initial part but I\'m not able to figure out what {3,19} is doing here:

/[A-Z][A-Za-z0-9\\s]{         


        
6条回答
  •  旧时难觅i
    2020-11-28 13:19

    {n,m} means "repeat the previous element at least n times and at most m times", so the expression
    [A-Za-z0-9\s]{3,19} means "match between 3 and 19 characters that are letters, digits, or whitespace". Note that repetition is greedy by default, so this will try to match as many characters as possible within that range (this doesn't come into play here, since the end of line anchor makes it so that there is really only one possibility for each match).

提交回复
热议问题