-3

I found a regex ^[A-Z]+[a-zA-Z''-'\s]*$ from this tutorial and does not understand the meaning of ''-'. What does it mean?

Edit

After reading the comments given to this question and the corresponding answer or deleted answer, now I know that this question must be deleted because this problem is about typo presented in the tutorial.

1 Answers1

2

When we leave out the other, well-understood parts of the character class, this remains: [''-'].

This construct has no use. It translates to "the character ' and the range from ' to '", which is syntactically valid in regex but functionally equivalent to ['].

In the context of the annotated C# class property on the MSDN:

[RegularExpression(@"^[A-Z]+[a-zA-Z''-'\s]*$")]
public string Genre { get; set; }

it's very likely simply a mistake by he tutorial author. The original intention is hard to guess. The following exactly the same thing.

[RegularExpression(@"^[A-Z]+[a-zA-Z'\s]*$")]
public string Genre { get; set; }
Tomalak
  • 306,836
  • 62
  • 485
  • 598
  • 1
    Does this answer add anything new compared to the answer on the dup from 2012? – Nisse Engström Jan 06 '18 at 08:51
  • No, it doesn't. (Except that there's less speculation about other languages than C#). Posted the answer before I saw the duplicate comment. – Tomalak Jan 06 '18 at 08:55
  • I'm asking because it seems odd that you would hammer it open and then post a virtually identical answer, but I guess you missed that it was closed as a dup of **two** questions. – Nisse Engström Jan 06 '18 at 10:02
  • Yeah, it was a bit of a mix-up. I re-opened it because ot the first (the generic "what does this regex mean?") and got to work on the answer before I noticed the other one. – Tomalak Jan 06 '18 at 15:19