Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Regular Expressions Razor Pages ASP.NET core @"^[A-Z]+[a-zA-Z""'\s-]*$"?

What does the '\s-]*$" at the end of @"^[A-Z]+[a-zA-Z""'\s-]*$" stand for? Am I right saying it means no white space and numbers allowed? I understand the start of it, just the last bit is confusing me. And it is the same for @"^[A-Z]+[a-zA-Z0-9""'\s-]*$"
Thanks in advance

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Anything inside of square brackets is matching a character or set of characters. So here. I recommend using a tool like Regexr to help you narrow down how it works with whatever input you can provide it.

But I’ll break down what this means.

^[A-Z]+[a-zA-Z""'\s-]*$

First of all, ^ means "the beginning of the input string" and $ means "the end of the input string" – So everything in between those characters is what is being matched

There are two character sets being matched

First is [A-Z]+ which means "match any capital letter from A to Z" and then the + at the end means to match the previous set at least one time, but as many times as possible

Next is [a-zA-Z""'\s-]* which is another set that matches:

  • a-z – any lowercase letters from a to z
  • A-Z – any uppercase letter from A to Z
  • " – any double quote mark
  • " – the same thing again, this is repeated and can probably be removed
  • ' – any single quote mark
  • \s – any whitespace character like a space or a tab
  • - – a hyphen/dash character

Finally the * at the end means "match the previous set zero or more times, as many times as possible

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading