1

I couldn't find any documentation on this symbol. What does "-?" mean when it precedes a parenthetical expression?

Update - The example I saw is the integer and float regex constraints on the WebIDL specification. Here is a direct link to the grammar appendix: http://dev.w3.org/2006/webapi/WebIDL/#idl-grammar

durron597
  • 31,968
  • 17
  • 99
  • 158
smartcaveman
  • 41,281
  • 29
  • 127
  • 212

1 Answers1

3

It's pretty standard for «-?» to mean "match the character «-» zero or one times".

$ perl -E'
   say "$_: ", /^aaa-?bbb\z/ ? "match" : "no match"
      for qw( aaabbb aaa-bbb aaa--bbb );
'
aaabbb: match
aaa-bbb: match
aaa--bbb: no match

I'd be extremely surprised if it didn't work the same way in C#.

ikegami
  • 367,544
  • 15
  • 269
  • 518
  • There is similar behavior with a `?` in C#. However, the `?` has to be a quantifier appearing at the end of a pattern. The Perl context that I saw had the entire pattern prefixed with `-?`. – smartcaveman Mar 29 '12 at 06:06
  • I could see that making sense for the regex, I was looking at (even as a prefix). Do you have any supporting documentation? – smartcaveman Mar 29 '12 at 06:10
  • 3
    Well, the regexes you linked are supposed to match numbers; numbers may or may not be negative; a negative number starts with a `-`. So it makes sense to start the pattern with `-?` to handle that. It's not a "prefix", it's normal regex. – Josh Y. Mar 29 '12 at 06:39