Closed Bug 856448 Opened 11 years ago Closed 10 years ago

Regular Expressions documentation: syntax of repetitions

Categories

(Developer Documentation Graveyard :: JavaScript, defect, P1)

defect

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: kengruven, Assigned: bruant.d)

Details

(Whiteboard: u=webdev p=1 c=JavaScript)

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.25 (KHTML, like Gecko) Version/6.0 Safari/536.25

Steps to reproduce:

In the MDN "Regular Expressions" documentation <https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Regular_Expressions#special-quantifier-range>, it says:

    "{n,m}    Where n and m are positive integers. Matches at least n and at most m occurrences of the preceding character. When either n or m is zero, it can be omitted."

The last sentence of this looks wrong to me.  I've not been able to reproduce this behavior in Firefox, or in Safari, or find it in the ECMAscript spec.



Actual results:

Empirically, in both Firefox and Safari, it seems you are able to omit m, only, when it is infinite (not zero).  Omitting n causes the RegExp object to treat the "{" character as a literal:

/^x{,3}$/.exec("x")
=> null

/^x{,3}$/.exec("x{,3}")
=> ["x{,3}"]

Specifically, whenever a "{" is followed by a non-digit character, it appears to be treated as a literal "{" character.


Expected results:

The ECMAscript spec RegExp grammar also makes no mention of being able to omit the first number in an {n,m} repetition: <http://www.ecma-international.org/ecma-262/5.1/#sec-15.10.1>.

I believe the documentation is incorrect.  Instead of the sentence:

    "When either n or m is zero, it can be omitted."

it should say something like:

    "When m is infinite, it can be omitted; n is always required."
Component: General → Landing pages
Priority: -- → P1
Product: Developer Documentation → Mozilla Developer Network
Oops, moved the wrong bug. Putting it back.
Assignee: nobody → eshepherd
Component: Landing pages → General
Product: Mozilla Developer Network → Developer Documentation
Assignee: eshepherd → bruant.d
Component: General → JavaScript
Whiteboard: u=webdev p=0
Whiteboard: u=webdev p=0 → u=webdev p=1 c=JavaScript
Status: UNCONFIRMED → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.