I was reading the “How Browsers Work” article here: How Browsers Work (It’s a great read.)
But at one point, they mention this as a rule of their grammar defining an integer:
INTEGER :0|[1-9][0-9]*
Is it, or is it not, exactly the same (and simpler) to write:
INTEGER :[1-9]*[0-9]
I couldn’t think of a case that did not satisfy both rules, nor a reason why the first rule would be preferred.
Is there a reason for including a simple base case (such as 0), or is it just pedantics?
These two expressions are different: the first one will take
101, but the second one wouldn’t. The expression from the book is pretty good at matching integers while disallowing leading zeros.