-2

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.

Second Person Shooter
  • 14,188
  • 21
  • 90
  • 165
  • source of the pattern? – hjpotter92 Jan 06 '18 at 08:01
  • @hjpotter92: See the link given above. – Second Person Shooter Jan 06 '18 at 08:03
  • 2
    `'-'` has no sense at all. It means `'`to `'`...Especially with the `'` before it it's even more useless! – csabinho Jan 06 '18 at 08:03
  • No, it means ASCII code from `"` to `'`. Which might be quite confusing... – csabinho Jan 06 '18 at 08:07
  • 1
    @PetervanderHeijden The question is valid. The OP asks about an unclear (and very probably useless) part in a regex he otherwise understands. – Tomalak Jan 06 '18 at 08:26
  • 2
    @Tomalak The linked (duplicate) question deals with exactly the same pattern https://stackoverflow.com/a/11854572/1190388 – hjpotter92 Jan 06 '18 at 08:31
  • Goto Regex101.com, paste your regex there, it will give you a very nice explanation – Sunil Jan 06 '18 at 08:38
  • @Artificial: Personally, I think the question is fine. The fact that it has been asked and answered before is not a problem. Your question even adds some new information: the source of the odd regex. The two answers that were deleted were completely irrelevant to your question, so that's entirely appropriate. – Nisse Engström Jan 07 '18 at 01:06

1 Answers1

3

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
  • 332,285
  • 67
  • 532
  • 628
  • 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