8 Literals
8.5 Regular Expression Literals
A regular expression literal is an input element that is converted to a RegExp object (see 22.2) 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 or calling the RegExp constructor as a function (see 22.2.3).
下面的productions描述了regular expression literal的语法 and are used by the input element scanner to find the end of the regular expression literal. The source text comprising the RegularExpressionBody and the RegularExpressionFlags are subsequently parsed again using the more stringent ECMAScript Regular Expression grammar (22.2.1).
An implementation may extend the ECMAScript Regular Expression grammar defined in 22.2.1, but it must not extend the RegularExpressionBody and RegularExpressionFlags productions defined below or the productions used by these productions.
语法
R e g u l a r E x p r e s s i o n L i t e r a l : : / R e g u l a r E x p r e s s i o n B o d y / R e g u l a r E x p r e s s i o n F l a g s RegularExpressionLiteral::\\\qquad / \enspace RegularExpressionBody\enspace / \enspace RegularExpressionFlags RegularExpressionLiteral::/RegularExpressionBody/RegularExpressionFlags
R e g u l a r E x p r e s s i o n B o d y : : R e g u l a r E x p r e s s i o n F i r s t C h a r R e g u l a r E x p r e s s i o n C h a r s RegularExpressionBody::\\\qquad RegularExpressionFirstChar \enspace RegularExpressionChars RegularExpressionBody::RegularExpressionFirstCharRegularExpressionChars
R e g u l a r E x p r e s s i o n C h a r s : : [empty] R e g u l a r E x p r e s s i o n C h a r s R e g u l a r E x p r e s s i o n C h a r RegularExpressionChars::\\ \qquad \text{[empty]} \\\qquad RegularExpressionChars\enspace RegularExpressionChar RegularExpressionChars::[empty]RegularExpressionCharsRegularExpressionChar