in reply to Oddness with regex quantifiers

I would think that a reason, is that there is no reasonable default.

Just as we have * for zero or more and + for 1 or more; either 0 or 1 would be equally valid defaults for {,n}. Since there is no hamming difference between them, how would you pick one over the other to be the default?

Replies are listed 'Best First'.
Re^2: Oddness with regex quantifiers
by talexb (Chancellor) on Nov 23, 2010 at 22:18 UTC

    Good point. I even suggested 0 earlier in this thread, but now I think 1 would be a better choice. I guess I'm spoiled by how well Perl deals with default values; I though it would DWIM in this case.

    And I was wrong. I'm now chastened, older and wider wiser; and I'm using {1,5} in my regex.

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

      Thank you for giving us the benefits of your experience.

      -t.b.b.