1

I am new to the regular expression format.

I just read a line of code in MVC data property, which is RegularExpression(@"^[A-Z]+[a-zA-Z''-'\s]*$"). I spent time in reading RE descriptions on the Internet, but still can not figure out what is the meaning of the part (''-') in the RegularExpression(@"^[A-Z]+[a-zA-Z''-'\s]*$").

Anyone who can give a hint on the (''-') part will be very appreciated.

Thanks. Yang

potatou
  • 11
  • 4
  • see the explanation at the right side in this https://regex101.com/r/jA7eF0/3 – Avinash Raj Mar 15 '15 at 11:56
  • I don't think this is a duplicate - I don't think it is answered on that very comprehensive overview of regex problems on SO. – Billy Moon Mar 15 '15 at 12:12
  • thanks Avinash Raj. The website is really helpful. As per to the explanation from the website, the ( ' ' -' ) seems could be replace by simple ( ' )? – potatou Mar 15 '15 at 12:18
  • yep. `['-']` means it would match all the chars which are present in-between the range `'` to `'`. A single quote only falls within this range , so it matches a single quote only. – Avinash Raj Mar 15 '15 at 12:38
  • 1
    This is not a duplicate. The "Wiki" question does not address the specifics of this question. The code comes from a Microsoft tutorial, which people see as authoritative. It's probably just wrong, but people come here looking for help, and redirecting to a generic answer doesn't help. – Dominic Cronin May 16 '16 at 19:29
  • I found this exact expression in an [old book](http://shop.oreilly.com/product/0636920022237.do) (a very well written one by the way) to validate a country name, and couldn't either make sense of the portion you asked about. I guess this is a mistake in the code transcription, two of the three quotes are likely other characters, I think it could be `.&,'`. [Asked again](https://stackoverflow.com/q/48125405/774575) years later, and no useful answer was still provided. Users who close such questions on the base of being duplicates, without actually checking, don't help their peers. – mins May 07 '20 at 12:44

1 Answers1

-2

[A-Z] means any character between A and Z (according to their character codes)

CyberDude
  • 7,397
  • 5
  • 24
  • 43