P. 1
ECMA-262 JavaScript 5

ECMA-262 JavaScript 5

|Views: 218|Likes:
Published by GregoryDonaghy

More info:

Published by: GregoryDonaghy on Mar 12, 2010
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less





A regular expression literal is an input element that is converted to a RegExp object (see 15.10) each time the
literal is evaluated. Two regular expression literals in a program evaluate to regular expression objects that
never compare as === to each other even if the two literals' contents are identical. A RegExp object may also
be created at runtime by new RegExp (see 15.10.4) or calling the RegExp constructor as a function (15.10.3).

The productions below describe the syntax for a regular expression literal and are used by the input element
scanner to find the end of the regular expression literal. The Strings of characters comprising the
RegularExpressionBody and the RegularExpressionFlags are passed uninterpreted to the regular expression
constructor, which interprets them according to its own, more stringent grammar. An implementation may
extend the regular expression constructor's grammar, but it must not extend the RegularExpressionBody and
RegularExpressionFlags productions or the productions used by these productions.


RegularExpressionLiteral ::
RegularExpressionBody / RegularExpressionFlags


© Ecma International 2009

RegularExpressionBody ::
RegularExpressionFirstChar RegularExpressionChars

RegularExpressionChars ::


RegularExpressionChars RegularExpressionChar

RegularExpressionFirstChar ::
RegularExpressionNonTerminator but not * or \ or / or [

RegularExpressionChar ::
RegularExpressionNonTerminator but not \ or / or [

RegularExpressionBackslashSequence ::

RegularExpressionNonTerminator ::
SourceCharacter but not LineTerminator

RegularExpressionClass ::
RegularExpressionClassChars ]

RegularExpressionClassChars ::


RegularExpressionClassChars RegularExpressionClassChar

RegularExpressionClassChar ::
RegularExpressionNonTerminator but not ] or \

RegularExpressionFlags ::


RegularExpressionFlags IdentifierPart


Regular expression literals may not be empty; instead of representing an empty regular expression literal, the
characters // start a single-line comment. To specify an empty regular expression, use: /(?:)/.


A regular expression literal evaluates to a value of the Object type that is an instance of the standard built-in
constructor RegExp. This value is determined in two steps: first, the characters comprising the regular
expression's RegularExpressionBody and RegularExpressionFlags production expansions are collected
uninterpreted into two Strings Pattern and Flags, respectively. Then each time the literal is evaluated, a new
object is created as if by the expression new RegExp(Pattern, Flags) where RegExp is the standard
built-in constructor with that name. The newly constructed object becomes the value of the
RegularExpressionLiteral. If the call to new RegExp would generate an error as specified in, the error
must be treated as an early error (Clause 16).

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->