help with regular expression

Can anyone tel me what this regular expression allows?  I know it allows a-z, both lower and uppercase, a length of 1 to 50, and spaces.  What does the ''-' part mean?  

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
isn't it the - characters:
any letters
any with space (\s)
allow repeat pattern 1 to 50 ({1,50})
HLRosenbergerAuthor Commented:
Also, if I do this :   "^[a-zA-Z\s\-\']{1,50}$"

This mean in addition to a-z (upper or lower),  spaces, hyphens and single quotes are allowed, correct?
HLRosenbergerAuthor Commented:
how does this:


mean the same as this:

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Your original regular expression literally means this:

From the start of the string (^),
match a single character from the following list (a through z, A through Z, ', ' through ' and any whitespace character),
as many times as possible; giving back as needed; 1 to 50 times ({1, 50}).

As such your original regular expression can also be rewritten as:


Which all mean the same thing as above.

HLRosenbergerAuthor Commented:
Saige thanks!

So the escape char is backslash correct?     How is this ''-' the same as \'  ??

And what does (?i) mean?
''-' is two single quotes, hyphen and one singe quote.

When an un-escaped character is used, the regular expression means literally the un-escaped character (unless that character must be escaped in order to match on it; e.g. the \ must be escaped to match on it, \\ means match a single \, literally).

That being said:
' means match the character ', literally.
['-'] means match a single character in the group ' through '.
\' means match the character ', literally.  The \ is the escape character and not needed since ' does not need to be escaped.

So the three examples above will match a single '; one time.

As for (?i); this means that whatever follows is matched without case sensitivity.

You can test this at


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HLRosenbergerAuthor Commented:
Thanks so much!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.