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

3
  • 2
    I'm wondering if he means e.g. (?-i:pattern) Commented Mar 29, 2012 at 4:31
  • @BoltClock, I have posted the context/link. Commented Mar 29, 2012 at 6:04
  • It's an optional -, it is written the same way (meaning the same thing) both regex flavors. Commented Mar 29, 2012 at 7:32

1 Answer 1

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#.

Sign up to request clarification or add additional context in comments.

3 Comments

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 -?.
I could see that making sense for the regex, I was looking at (even as a prefix). Do you have any supporting documentation?
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.