22 Text Processing

22.1 String Objects

22.1.1 The String Constructor

String constructorは:

  • %String%です。
  • global object"String" propertyのinitial valueです。
  • constructorとして呼び出されたとき、新しいString objectを作成およびinitializeします。
  • constructorとしてではなくfunctionとして呼び出されたとき、type conversionを実行します。
  • class definitionのextends clauseのvalueとして使用できます。指定されたString behaviourをinheritしようとするsubclass constructorsは、[[StringData]] internal slotを持つsubclass instanceを作成およびinitializeするために、String constructorへのsuper callを含まなければなりません。

22.1.1.1 String ( value )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. valueがpresentでないなら、
    1. stringをempty Stringとする。
  2. そうでなければ、
    1. NewTargetがundefinedであり、かつvalueがSymbolなら、SymbolDescriptiveString(value)を返す。
    2. stringを ? ToString(value) とする。
  3. NewTargetがundefinedなら、stringを返す。
  4. StringCreate(string, ? GetPrototypeFromConstructor(NewTarget, "%String.prototype%"))を返す。

22.1.2 Properties of the String Constructor

String constructorは:

  • valueが%Function.prototype%である[[Prototype]] internal slotを持ちます。
  • 次のpropertiesを持ちます:

22.1.2.1 String.fromCharCode ( ...codeUnits )

このfunctionは、rest parameter codeUnitsを形成する任意の数のargumentsで呼び出すことができます。

これは呼び出されたとき、次のstepsを実行します:

  1. resultをempty Stringとする。
  2. codeUnitsの各要素nextについて、以下を行う
    1. nextCUを、numeric valueが(? ToUint16(next))であるcode unitとする。
    2. resultresultnextCUstring-concatenationに設定する。
  3. resultを返す。

このfunctionの"length" propertyは1𝔽です。

22.1.2.2 String.fromCodePoint ( ...codePoints )

このfunctionは、rest parameter codePointsを形成する任意の数のargumentsで呼び出すことができます。

これは呼び出されたとき、次のstepsを実行します:

  1. resultをempty Stringとする。
  2. codePointsの各要素nextについて、以下を行う
    1. nextCPを ? ToNumber(next) とする。
    2. nextCPintegral Numberでないなら、RangeError例外をthrowする。
    3. (nextCP) < 0または(nextCP) > 0x10FFFFなら、RangeError例外をthrowする。
    4. resultresultUTF16EncodeCodePoint((nextCP))のstring-concatenationに設定する。
  3. Assert: codePointsがemptyなら、resultはempty Stringである。
  4. resultを返す。

このfunctionの"length" propertyは1𝔽です。

22.1.2.3 String.prototype

String.prototypeのinitial valueはString prototype objectです。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

22.1.2.4 String.raw ( template, ...substitutions )

このfunctionはvariable number of argumentsで呼び出すことができます。first argumentはtemplateであり、remaining argumentsはList substitutionsを形成します。

これは呼び出されたとき、次のstepsを実行します:

  1. substitutionCountsubstitutions内のelementsの数とする。
  2. cookedを ? ToObject(template) とする。
  3. literalsを ? ToObject(? Get(cooked, "raw")) とする。
  4. literalCountを ? LengthOfArrayLike(literals) とする。
  5. literalCount ≤ 0なら、empty Stringを返す。
  6. resultをempty Stringとする。
  7. nextIndexを0とする。
  8. 繰り返す:
    1. nextLiteralValueを ? Get(literals, ! ToString(𝔽(nextIndex))) とする。
    2. nextLiteralを ? ToString(nextLiteralValue) とする。
    3. resultresultnextLiteralstring-concatenationに設定する。
    4. nextIndex + 1 = literalCountなら、resultを返す。
    5. nextIndex < substitutionCountなら、
      1. nextSubValuesubstitutions[nextIndex]とする。
      2. nextSubを ? ToString(nextSubValue) とする。
      3. resultresultnextSubstring-concatenationに設定する。
    6. nextIndexnextIndex + 1に設定する。
Note

このfunctionはTagged Template(13.3.11)のtag functionとして使用することを意図しています。そのように呼び出されたとき、first argumentはwell formed template objectであり、rest parameterはsubstitution valuesを含みます。

22.1.3 Properties of the String Prototype Object

String prototype objectは:

  • %String.prototype%です。
  • String exotic objectであり、そのようなobjectsに対して指定されたinternal methodsを持ちます。
  • valueがempty Stringである[[StringData]] internal slotを持ちます。
  • initial valueが+0𝔽であり、attributesが { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false } である"length" propertyを持ちます。
  • valueが%Object.prototype%である[[Prototype]] internal slotを持ちます。

明示的に別途述べられない限り、以下で定義されるString prototype objectのmethodsはgenericではなく、それらに渡されるthis valueは、String valueであるか、String valueへinitialize済みの[[StringData]] internal slotを持つobjectでなければなりません。

22.1.3.1 String.prototype.at ( index )

  1. thisValuethis valueとする。
  2. RequireObjectCoercible(thisValue)を実行する。
  3. stringを ? ToString(thisValue) とする。
  4. lengthstringのlengthとする。
  5. relativeIndexを ? ToIntegerOrInfinity(index) とする。
  6. relativeIndex ≥ 0なら、
    1. krelativeIndexとする。
  7. そうでなければ、
    1. klength + relativeIndexとする。
  8. k < 0またはklengthなら、undefinedを返す。
  9. stringkからk + 1までのsubstringを返す。

22.1.3.2 String.prototype.charAt ( position )

Note 1

このmethodは、このobjectをStringへconvertしたresultであるString value内のindex positionにあるcode unitを含むsingle element Stringを返します。そのindexにelementが存在しない場合、resultはempty Stringです。resultはString valueであり、String objectではありません。

posintegral Numberである場合、x.charAt(pos)のresultはx.substring(pos, pos + 1)のresultとequivalentです。

このmethodは呼び出されたとき、次のstepsを実行します:

  1. thisValuethis valueとする。
  2. RequireObjectCoercible(thisValue)を実行する。
  3. stringを ? ToString(thisValue) とする。
  4. positionを ? ToIntegerOrInfinity(position) に設定する。
  5. sizestringのlengthとする。
  6. position < 0またはpositionsizeなら、empty Stringを返す。
  7. stringpositionからposition + 1までのsubstringを返す。
Note 2

このmethodは意図的にgenericです;そのthis valueがString objectであることをrequireしません。したがって、methodとして使用するために他の種類のobjectsへtransferできます。

22.1.3.3 String.prototype.charCodeAt ( position )

Note 1

このmethodは、このobjectをStringへconvertしたresultであるString内のindex positionにあるcode unitのnumeric valueであるNumber(216未満のnon-negative integral Number)を返します。そのindexにelementが存在しない場合、resultはNaNです。

このmethodは呼び出されたとき、次のstepsを実行します:

  1. thisValuethis valueとする。
  2. RequireObjectCoercible(thisValue)を実行する。
  3. stringを ? ToString(thisValue) とする。
  4. positionを ? ToIntegerOrInfinity(position) に設定する。
  5. sizestringのlengthとする。
  6. position < 0またはpositionsizeなら、NaNを返す。
  7. String string内のindex positionにあるcode unitのnumeric valueに対するNumber valueを返す。
Note 2

このmethodは意図的にgenericです;そのthis valueがString objectであることをrequireしません。したがって、methodとして使用するために他の種類のobjectsへtransferできます。

22.1.3.4 String.prototype.codePointAt ( position )

Note 1

このmethodは、このobjectをStringへconvertしたresultであるString内のindex positionのstring elementから始まるUTF-16 encoded code point(6.1.4)のnumeric valueである、0x10FFFF𝔽以下のnon-negative integral Numberを返します。そのindexにelementが存在しない場合、resultはundefinedです。valid UTF-16 surrogate pairpositionでbeginしない場合、resultはpositionにあるcode unitです。

このmethodは呼び出されたとき、次のstepsを実行します:

  1. thisValuethis valueとする。
  2. RequireObjectCoercible(thisValue)を実行する。
  3. stringを ? ToString(thisValue) とする。
  4. positionを ? ToIntegerOrInfinity(position) に設定する。
  5. sizestringのlengthとする。
  6. position < 0またはpositionsizeなら、undefinedを返す。
  7. codePointCodePointAt(string, position)とする。
  8. 𝔽(codePoint.[[CodePoint]])を返す。
Note 2

このmethodは意図的にgenericです;そのthis valueがString objectであることをrequireしません。したがって、methodとして使用するために他の種類のobjectsへtransferできます。

22.1.3.5 String.prototype.concat ( ...args )

Note 1

このmethodが呼び出されると、this value(Stringへconvertedされる)のcode unitsに、Stringへconvertedされた各argumentのcode unitsがfollowしたものからなるString valueを返します。resultはString valueであり、String objectではありません。

このmethodは呼び出されたとき、次のstepsを実行します:

  1. thisValuethis valueとする。
  2. RequireObjectCoercible(thisValue)を実行する。
  3. stringを ? ToString(thisValue) とする。
  4. resultstringとする。
  5. argsの各要素nextについて、以下を行う
    1. nextStringを ? ToString(next) とする。
    2. resultresultnextStringstring-concatenationに設定する。
  6. resultを返す。

このmethodの"length" propertyは1𝔽です。

Note 2

このmethodは意図的にgenericです;そのthis valueがString objectであることをrequireしません。したがって、methodとして使用するために他の種類のobjectsへtransferできます。

22.1.3.6 String.prototype.constructor

String.prototype.constructorのinitial valueは%String%です。

22.1.3.7 String.prototype.endsWith ( searchString [ , endPosition ] )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. thisValuethis valueとする。
  2. RequireObjectCoercible(thisValue)を実行する。
  3. stringを ? ToString(thisValue) とする。
  4. isRegexpを ? IsRegExp(searchString) とする。
  5. isRegexptrueなら、TypeError例外をthrowする。
  6. searchStringを ? ToString(searchString) に設定する。
  7. lengthstringのlengthとする。
  8. endPositionundefinedなら、positionlengthとする;そうでなければ、positionを ? ToIntegerOrInfinity(endPosition) とする。
  9. endpositionを0とlengthの間にclampingしたresultとする。
  10. searchLengthsearchStringのlengthとする。
  11. searchLength = 0なら、trueを返す。
  12. startend - searchLengthとする。
  13. start < 0なら、falseを返す。
  14. substringstringstartからendまでのsubstringとする。
  15. substringsearchStringなら、trueを返す。
  16. falseを返す。
Note 1

first argumentがRegExpである場合にexceptionをthrowすることは、そのようなargument valuesをallowするextensionsをfuture editionsがdefineできるようにするために指定されています。

Note 2

このmethodは意図的にgenericです;そのthis valueがString objectであることをrequireしません。したがって、methodとして使用するために他の種類のobjectsへtransferできます。

22.1.3.8 String.prototype.includes ( searchString [ , position ] )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. thisValuethis valueとする。
  2. RequireObjectCoercible(thisValue)を実行する。
  3. stringを ? ToString(thisValue) とする。
  4. isRegexpを ? IsRegExp(searchString) とする。
  5. isRegexptrueなら、TypeError例外をthrowする。
  6. searchStringを ? ToString(searchString) に設定する。
  7. positionIntを ? ToIntegerOrInfinity(position) とする。
  8. Assert: positionundefinedなら、positionIntは0である。
  9. lengthstringのlengthとする。
  10. startpositionIntを0とlengthの間にclampingしたresultとする。
  11. indexStringIndexOf(string, searchString, start)とする。
  12. indexnot-foundなら、falseを返す。
  13. trueを返す。
Note 1

searchStringが、このobjectをStringへconvertしたresultのsubstringとして、position以上である1つ以上のindicesにappearsする場合、このfunctionはtrueを返します;そうでなければfalseを返します。positionundefinedなら、String全体をsearchするために0がassumedされます。

Note 2

first argumentがRegExpである場合にexceptionをthrowすることは、そのようなargument valuesをallowするextensionsをfuture editionsがdefineできるようにするために指定されています。

Note 3

このmethodは意図的にgenericです;そのthis valueがString objectであることをrequireしません。したがって、methodとして使用するために他の種類のobjectsへtransferできます。

22.1.3.9 String.prototype.indexOf ( searchString [ , position ] )

Note 1

searchStringが、このobjectをStringへconvertしたresultのsubstringとして、position以上である1つ以上のindicesにappearsする場合、そのようなsmallest indexが返されます;そうでなければ、-1𝔽が返されます。positionundefinedなら、String全体をsearchするために+0𝔽がassumedされます。

このmethodは呼び出されたとき、次のstepsを実行します:

  1. thisValuethis valueとする。
  2. RequireObjectCoercible(thisValue)を実行する。
  3. stringを ? ToString(thisValue) とする。
  4. searchStringを ? ToString(searchString) に設定する。
  5. positionIntを ? ToIntegerOrInfinity(position) とする。
  6. Assert: positionundefinedなら、positionIntは0である。
  7. lengthstringのlengthとする。
  8. startpositionIntを0とlengthの間にclampingしたresultとする。
  9. resultStringIndexOf(string, searchString, start)とする。
  10. resultnot-foundなら、-1𝔽を返す。
  11. 𝔽(result)を返す。
Note 2

このmethodは意図的にgenericです;そのthis valueがString objectであることをrequireしません。したがって、methodとして使用するために他の種類のobjectsへtransferできます。

22.1.3.10 String.prototype.isWellFormed ( )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. thisValuethis valueとする。
  2. RequireObjectCoercible(thisValue)を実行する。
  3. stringを ? ToString(thisValue) とする。
  4. IsStringWellFormedUnicode(string)を返す。

22.1.3.11 String.prototype.lastIndexOf ( searchString [ , position ] )

Note 1

searchStringが、このobjectをStringへconvertしたresultのsubstringとして、position以下である1つ以上のindicesにappearsする場合、そのようなgreatest indexが返されます;そうでなければ、-1𝔽が返されます。positionundefinedなら、String全体をsearchするためにString valueのlengthがassumedされます。

このmethodは呼び出されたとき、次のstepsを実行します:

  1. thisValuethis valueとする。
  2. RequireObjectCoercible(thisValue)を実行する。
  3. stringを ? ToString(thisValue) とする。
  4. searchStringを ? ToString(searchString) に設定する。
  5. numberPositionを ? ToNumber(position) とする。
  6. Assert: positionundefinedなら、numberPositionNaNである。
  7. numberPositionNaNなら、positionを+∞に設定する;そうでなければ、positionを ! ToIntegerOrInfinity(numberPosition) に設定する。
  8. lengthstringのlengthとする。
  9. searchLengthsearchStringのlengthとする。
  10. length < searchLengthなら、-1𝔽を返す。
  11. startpositionを0とlength - searchLengthの間にclampingしたresultとする。
  12. resultStringLastIndexOf(string, searchString, start)とする。
  13. resultnot-foundなら、-1𝔽を返す。
  14. 𝔽(result)を返す。
Note 2

このmethodは意図的にgenericです;そのthis valueがString objectであることをrequireしません。したがって、methodとして使用するために他の種類のobjectsへtransferできます。

22.1.3.12 String.prototype.localeCompare ( that [ , reserved1 [ , reserved2 ] ] )

ECMA-402 Internationalization APIを含むECMAScript implementationは、このmethodをECMA-402 specificationで指定される通りにimplementしなければなりません。ECMAScript implementationがECMA-402 APIを含まない場合、このmethodの次のspecificationが使用されます:

このmethodは、this value(String stringへconvertedされる)とthat(String thatValueへconvertedされる)とのimplementation-defined locale-sensitive String comparisonのresultを表す、NaN以外のNumberを返します。resultは、host environmentのcurrent localeのconventionsに従ったString valuesのsort orderに対応することを意図しており、stringthatValueより前にorderedされるときnegative、stringthatValueより後にorderedされるときpositive、その他すべての場合にはzero(stringthatValueの間にrelative orderingがないことを表す)になります。

comparisonsを実行する前に、このmethodはStringsをprepareするために次のstepsを実行します:

  1. thisValuethis valueとする。
  2. RequireObjectCoercible(thisValue)を実行する。
  3. stringを ? ToString(thisValue) とする。
  4. thatValueを ? ToString(that) とする。

このmethodのoptional secondおよびthird parametersのmeaningはECMA-402 specificationで定義されます;ECMA-402 supportを含まないimplementationsは、それらのparameter positionsに他のinterpretationをassignしてはなりません。

actual return valuesは、それらにadditional informationをencodingできるようimplementation-definedですが、このmethodは、two argumentsのmethodとしてconsideredされるとき、すべてのStringsのset上でtotal orderingを定義するconsistent comparatorであることがrequiredです。このmethodはまた、Unicode Standardに従うcanonical equivalenceをrecognizeおよびhonourすることがrequiredであり、canonically equivalentなdistinguishable Stringsを比較するときに+0𝔽を返すことを含みます。

Note 1

このmethod自体はArray.prototype.sortへのargumentとして直接適していません。後者はtwo argumentsのfunctionをrequireするためです。

Note 2

このmethodは、ECMAScript environmentがhost environmentから利用できる任意のlanguage- and/or locale-sensitive comparison functionalityにrelyしてもよく、host environmentのcurrent localeのconventionsに従ってcompareすることを意図しています。しかし、comparison capabilitiesにかかわらず、このmethodはUnicode Standardに従うcanonical equivalenceをrecognizeおよびhonourしなければなりません—例えば、以下のcomparisonsはすべて+0𝔽を返さなければなりません:

// Å ANGSTROM SIGN vs.
// Å LATIN CAPITAL LETTER A + COMBINING RING ABOVE
"\u212B".localeCompare("A\u030A")

// Ω OHM SIGN vs.
// Ω GREEK CAPITAL LETTER OMEGA
"\u2126".localeCompare("\u03A9")

// ṩ LATIN SMALL LETTER S WITH DOT BELOW AND DOT ABOVE vs.
// ṩ LATIN SMALL LETTER S + COMBINING DOT ABOVE + COMBINING DOT BELOW
"\u1E69".localeCompare("s\u0307\u0323")

// ḍ̇ LATIN SMALL LETTER D WITH DOT ABOVE + COMBINING DOT BELOW vs.
// ḍ̇ LATIN SMALL LETTER D WITH DOT BELOW + COMBINING DOT ABOVE
"\u1E0B\u0323".localeCompare("\u1E0D\u0307")

// 가 HANGUL CHOSEONG KIYEOK + HANGUL JUNGSEONG A vs.
// 가 HANGUL SYLLABLE GA
"\u1100\u1161".localeCompare("\uAC00")

canonical equivalenceのdefinitionおよびdiscussionについては、Unicode Standardのchapters 2および3に加えて、Unicode Standard Annex #15, Unicode Normalization FormsおよびUnicode Technical Note #5, Canonical Equivalence in Applicationsを参照してください。Unicode Technical Standard #10, Unicode Collation Algorithmも参照してください。

このmethodは、Unicode Standardのchapter 3, section 3.7で定義されるUnicode compatibility equivalentsまたはcompatibility decompositionsをhonourすべきでないことがrecommendedされます。

Note 3

このmethodは意図的にgenericです;そのthis valueがString objectであることをrequireしません。したがって、methodとして使用するために他の種類のobjectsへtransferできます。

22.1.3.13 String.prototype.match ( regexpOrPattern )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. thisValuethis valueとする。
  2. RequireObjectCoercible(thisValue)を実行する。
  3. regexpOrPatternがObjectなら、
    1. matcherを ? GetMethod(regexpOrPattern, %Symbol.match%) とする。
    2. matcherundefinedでないなら、
      1. Call(matcher, regexpOrPattern, « thisValue »)を返す。
  4. stringを ? ToString(thisValue) とする。
  5. regexpを ? RegExpCreate(regexpOrPattern, undefined) とする。
  6. Invoke(regexp, %Symbol.match%, « string »)を返す。
Note

このmethodは意図的にgenericです;そのthis valueがString objectであることをrequireしません。したがって、methodとして使用するために他の種類のobjectsへtransferできます。

22.1.3.14 String.prototype.matchAll ( regexpOrPattern )

このmethodは、this valueを表すStringに対してregexpOrPatternとのregular expression matchを実行し、match resultsをyieldするiteratorを返します。各match resultは、matched portion of the Stringをfirst elementとして含み、その後にcapturing groupsによってmatchedされた任意のportionsが続くArrayです。regular expressionが決してmatchしない場合、返されるiteratorはmatch resultsをyieldしません。

これは呼び出されたとき、次のstepsを実行します:

  1. thisValuethis valueとする。
  2. RequireObjectCoercible(thisValue)を実行する。
  3. regexpOrPatternがObjectなら、
    1. isRegexpを ? IsRegExp(regexpOrPattern) とする。
    2. isRegexptrueなら、
      1. flagsを ? Get(regexpOrPattern, "flags") とする。
      2. RequireObjectCoercible(flags)を実行する。
      3. ToString(flags)が"g"を含まないなら、TypeError例外をthrowする。
    3. matcherを ? GetMethod(regexpOrPattern, %Symbol.matchAll%) とする。
    4. matcherundefinedでないなら、
      1. Call(matcher, regexpOrPattern, « thisValue »)を返す。
  4. stringを ? ToString(thisValue) とする。
  5. regexpを ? RegExpCreate(regexpOrPattern, "g") とする。
  6. Invoke(regexp, %Symbol.matchAll%, « string »)を返す。
Note 1
このmethodは意図的にgenericです;そのthis valueがString objectであることをrequireしません。したがって、methodとして使用するために他の種類のobjectsへtransferできます。
Note 2
String.prototype.splitと同様に、String.prototype.matchAllは通常、そのinputsをmutateせずにactするようにdesignedされています。

22.1.3.15 String.prototype.normalize ( [ form ] )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. thisValuethis valueとする。
  2. RequireObjectCoercible(thisValue)を実行する。
  3. stringを ? ToString(thisValue) とする。
  4. formundefinedなら、form"NFC"に設定する。
  5. そうでなければ、formを ? ToString(form) に設定する。
  6. form"NFC""NFD""NFKC"、または"NFKD"のいずれでもないなら、RangeError例外をthrowする。
  7. normalを、the latest Unicode Standard, Normalization Formsで指定される通り、formによってnamedされたnormalization formへstringをnormalizingしたresultであるString valueとする。
  8. normalを返す。
Note

このmethodは意図的にgenericです;そのthis valueがString objectであることをrequireしません。したがって、methodとして使用するために他の種類のobjectsへtransferできます。

22.1.3.16 String.prototype.padEnd ( maxLength [ , fillString ] )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. thisValuethis valueとする。
  2. RequireObjectCoercible(thisValue)を実行する。
  3. StringPaddingBuiltinsImpl(thisValue, maxLength, fillString, end)を返す。

22.1.3.17 String.prototype.padStart ( maxLength [ , fillString ] )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. thisValuethis valueとする。
  2. RequireObjectCoercible(thisValue)を実行する。
  3. StringPaddingBuiltinsImpl(thisValue, maxLength, fillString, start)を返す。

22.1.3.17.1 StringPaddingBuiltinsImpl ( thisValue, maxLength, fillString, placement )

The abstract operation StringPaddingBuiltinsImpl takes arguments thisValue (an ECMAScript language value), maxLength (an ECMAScript language value), fillString (an ECMAScript language value), and placement (start or end) and returns either a normal completion containing a String or a throw completion. It performs the following steps when called:

  1. stringを ? ToString(thisValue) とする。
  2. intMaxLength(? ToLength(maxLength))とする。
  3. stringLengthstringのlengthとする。
  4. intMaxLengthstringLengthなら、stringを返す。
  5. fillStringundefinedなら、fillStringをcode unit 0x0020 (SPACE)のみからなるString valueに設定する。
  6. そうでなければ、fillStringを ? ToString(fillString) に設定する。
  7. StringPad(string, intMaxLength, fillString, placement)を返す。

22.1.3.17.2 StringPad ( string, maxLength, fillString, placement )

The abstract operation StringPad takes arguments string (a String), maxLength (a non-negative integer), fillString (a String), and placement (start or end) and returns a String. It performs the following steps when called:

  1. stringLengthstringのlengthとする。
  2. maxLengthstringLengthなら、stringを返す。
  3. fillStringがempty Stringなら、stringを返す。
  4. fillLengthmaxLength - stringLengthとする。
  5. truncatedStringFillerを、fillStringのrepeated concatenationsからなり、length fillLengthにtruncatedされたString valueとする。
  6. placementstartなら、truncatedStringFillerstringstring-concatenationを返す。
  7. stringtruncatedStringFillerstring-concatenationを返す。
Note 1

argument maxLengthは、stringのlengthより小さくならないようにclampedされます。

Note 2

argument fillString" "(code unit 0x0020 SPACEからなるString value)をdefaultとします。

22.1.3.17.3 ToZeroPaddedDecimalString ( n, minLength )

The abstract operation ToZeroPaddedDecimalString takes arguments n (a non-negative integer) and minLength (a non-negative integer) and returns a String. It performs the following steps when called:

  1. stringをdecimal numberとしてformattedされたnのString representationとする。
  2. StringPad(string, minLength, "0", start)を返す。

22.1.3.18 String.prototype.repeat ( count )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. thisValuethis valueとする。
  2. RequireObjectCoercible(thisValue)を実行する。
  3. stringを ? ToString(thisValue) とする。
  4. nを ? ToIntegerOrInfinity(count) とする。
  5. n < 0またはn = +∞なら、RangeError例外をthrowする。
  6. n = 0なら、empty Stringを返す。
  7. stringn個のcopiesをappended togetherして作られたString valueを返す。
Note 1

このmethodは、this value(Stringへconvertedされる)のcode unitsがcount回repeatedされたものからなるString valueを作成します。

Note 2

このmethodは意図的にgenericです;そのthis valueがString objectであることをrequireしません。したがって、methodとして使用するために他の種類のobjectsへtransferできます。

22.1.3.19 String.prototype.replace ( searchValue, replaceValue )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. thisValuethis valueとする。
  2. RequireObjectCoercible(thisValue)を実行する。
  3. searchValueがObjectなら、
    1. replacerを ? GetMethod(searchValue, %Symbol.replace%) とする。
    2. replacerundefinedでないなら、
      1. Call(replacer, searchValue, « thisValue, replaceValue »)を返す。
  4. stringを ? ToString(thisValue) とする。
  5. searchStringを ? ToString(searchValue) とする。
  6. functionalReplaceIsCallable(replaceValue)とする。
  7. functionalReplacefalseなら、
    1. replaceValueを ? ToString(replaceValue) に設定する。
  8. searchLengthsearchStringのlengthとする。
  9. positionStringIndexOf(string, searchString, 0)とする。
  10. positionnot-foundなら、stringを返す。
  11. precedingstringの0からpositionまでのsubstringとする。
  12. followingstringposition + searchLengthからのsubstringとする。
  13. functionalReplacetrueなら、
    1. replacementを ? ToString(? Call(replaceValue, undefined, « searchString, 𝔽(position), string »)) とする。
  14. そうでなければ、
    1. Assert: replaceValueはStringである。
    2. capturesを新しい空のListとする。
    3. replacementを ! GetSubstitution(searchString, string, position, captures, undefined, replaceValue) とする。
  15. precedingreplacement、およびfollowingstring-concatenationを返す。
Note

このmethodは意図的にgenericです;そのthis valueがString objectであることをrequireしません。したがって、methodとして使用するために他の種類のobjectsへtransferできます。

22.1.3.19.1 GetSubstitution ( matched, string, position, captures, namedCaptures, replacementTemplate )

The abstract operation GetSubstitution takes arguments matched (a String), string (a String), position (a non-negative integer), captures (a List of either Strings or undefined), namedCaptures (an Object or undefined), and replacementTemplate (a String) and returns either a normal completion containing a String or a throw completion. このabstract operationのpurposesにおいて、decimal digitは0x0030 (DIGIT ZERO)から0x0039 (DIGIT NINE)までのinclusive interval内のcode unitです。 It performs the following steps when called:

  1. stringLengthstringのlengthとする。
  2. Assert: positionstringLengthである。
  3. resultをempty Stringとする。
  4. templateRemainderreplacementTemplateとする。
  5. templateRemainderがempty Stringでない間、繰り返す
    1. NOTE: 以下のstepsはreftemplateRemainderのprefix)をisolateし、refReplacement(そのreplacement)をdetermineし、そのreplacementをresultへappendする。
    2. templateRemainder"$$"で始まるなら、
      1. ref"$$"とする。
      2. refReplacement"$"とする。
    3. そうでなく、templateRemainder"$`"で始まるなら、
      1. ref"$`"とする。
      2. refReplacementstringの0からpositionまでのsubstringとする。
    4. そうでなく、templateRemainder"$&"で始まるなら、
      1. ref"$&"とする。
      2. refReplacementmatchedとする。
    5. そうでなく、templateRemainder"$'"(0x0024 (DOLLAR SIGN) followed by 0x0027 (APOSTROPHE))で始まるなら、
      1. ref"$'"とする。
      2. matchLengthmatchedのlengthとする。
      3. tailPositionposition + matchLengthとする。
      4. refReplacementstringmin(tailPosition, stringLength)からのsubstringとする。
      5. NOTE: このabstract operationが、"exec" propertyがintrinsic %RegExp.prototype.exec%でないobject上の%RegExp.prototype%のintrinsic %Symbol.replace% methodへのcallによってinvokedされた場合にのみ、tailPositionstringLengthを超え得る。
    6. そうでなく、templateRemainder"$"の後に1つ以上のdecimal digitsが続くもので始まるなら、
      1. templateRemainder"$"の後に2つ以上のdecimal digitsが続くもので始まるなら、digitCountを2とする;そうでなければ、digitCountを1とする。
      2. digitstemplateRemainderの1から1 + digitCountまでのsubstringとする。
      3. index(StringToNumber(digits))とする。
      4. Assert: 0 ≤ index ≤ 99である。
      5. captureLengthcaptures内のelementsの数とする。
      6. index > captureLengthかつdigitCount = 2なら、
        1. NOTE: two-digit replacement patternがcapturing groupsのcountを超えるindexをspecifyする場合、それはone-digit replacement patternの後にliteral digitが続くものとして扱われる。
        2. digitCountを1に設定する。
        3. digitsdigitsの0から1までのsubstringに設定する。
        4. index(StringToNumber(digits))に設定する。
      7. reftemplateRemainderの0から1 + digitCountまでのsubstringとする。
      8. 1 ≤ indexcaptureLengthなら、
        1. capturecaptures[index - 1]とする。
        2. captureundefinedなら、
          1. refReplacementをempty Stringとする。
        3. そうでなければ、
          1. refReplacementcaptureとする。
      9. そうでなければ、
        1. refReplacementrefとする。
    7. そうでなく、templateRemainder"$<"で始まるなら、
      1. gtPositionStringIndexOf(templateRemainder, ">", 0)とする。
      2. gtPositionnot-foundまたはnamedCapturesundefinedなら、
        1. ref"$<"とする。
        2. refReplacementrefとする。
      3. そうでなければ、
        1. reftemplateRemainderの0からgtPosition + 1までのsubstringとする。
        2. groupNametemplateRemainderの2からgtPositionまでのsubstringとする。
        3. Assert: namedCapturesはObjectである。
        4. captureを ? Get(namedCaptures, groupName) とする。
        5. captureundefinedなら、
          1. refReplacementをempty Stringとする。
        6. そうでなければ、
          1. refReplacementを ? ToString(capture) とする。
    8. そうでなければ、
      1. reftemplateRemainderの0から1までのsubstringとする。
      2. refReplacementrefとする。
    9. refLengthrefのlengthとする。
    10. templateRemaindertemplateRemainderrefLengthからのsubstringに設定する。
    11. resultresultrefReplacementstring-concatenationに設定する。
  6. resultを返す。

22.1.3.20 String.prototype.replaceAll ( searchValue, replaceValue )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. thisValuethis valueとする。
  2. RequireObjectCoercible(thisValue)を実行する。
  3. searchValueがObjectなら、
    1. isRegexpを ? IsRegExp(searchValue) とする。
    2. isRegexptrueなら、
      1. flagsを ? Get(searchValue, "flags") とする。
      2. RequireObjectCoercible(flags)を実行する。
      3. ToString(flags)が"g"を含まないなら、TypeError例外をthrowする。
    3. replacerを ? GetMethod(searchValue, %Symbol.replace%) とする。
    4. replacerundefinedでないなら、
      1. Call(replacer, searchValue, « thisValue, replaceValue »)を返す。
  4. stringを ? ToString(thisValue) とする。
  5. searchStringを ? ToString(searchValue) とする。
  6. functionalReplaceIsCallable(replaceValue)とする。
  7. functionalReplacefalseなら、
    1. replaceValueを ? ToString(replaceValue) に設定する。
  8. searchLengthsearchStringのlengthとする。
  9. advanceBymax(1, searchLength)とする。
  10. matchPositionsを新しい空のListとする。
  11. positionStringIndexOf(string, searchString, 0)とする。
  12. positionnot-foundでない間、繰り返す
    1. positionmatchPositionsへappendする。
    2. positionStringIndexOf(string, searchString, position + advanceBy)に設定する。
  13. endOfLastMatchを0とする。
  14. resultをempty Stringとする。
  15. matchPositionsの各要素matchPositionについて、以下を行う
    1. preservedstringendOfLastMatchからmatchPositionまでのsubstringとする。
    2. functionalReplacetrueなら、
      1. replacementを ? ToString(? Call(replaceValue, undefined, « searchString, 𝔽(matchPosition), string »)) とする。
    3. そうでなければ、
      1. Assert: replaceValueはStringである。
      2. capturesを新しい空のListとする。
      3. replacementを ! GetSubstitution(searchString, string, matchPosition, captures, undefined, replaceValue) とする。
    4. resultresultpreserved、およびreplacementstring-concatenationに設定する。
    5. endOfLastMatchmatchPosition + searchLengthに設定する。
  16. endOfLastMatch < stringのlengthなら、
    1. resultresultstringendOfLastMatchからのsubstringstring-concatenationに設定する。
  17. resultを返す。

22.1.3.21 String.prototype.search ( regexpOrPattern )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. thisValuethis valueとする。
  2. RequireObjectCoercible(thisValue)を実行する。
  3. regexpOrPatternがObjectなら、
    1. searcherを ? GetMethod(regexpOrPattern, %Symbol.search%) とする。
    2. searcherundefinedでないなら、
      1. Call(searcher, regexpOrPattern, « thisValue »)を返す。
  4. stringを ? ToString(thisValue) とする。
  5. regexpを ? RegExpCreate(regexpOrPattern, undefined) とする。
  6. Invoke(regexp, %Symbol.search%, « string »)を返す。
Note

このmethodは意図的にgenericです;そのthis valueがString objectであることをrequireしません。したがって、methodとして使用するために他の種類のobjectsへtransferできます。

22.1.3.22 String.prototype.slice ( start, end )

このmethodは、このobjectをStringへconvertしたresultのsubstringを返します。これはindex startから始まり、index endまで(ただしendを含まない)runningします(またはendundefinedならStringのendまで)。startがnegativeなら、sourceLengthをStringのlengthとして、sourceLength + startとして扱われます。endがnegativeなら、sourceLengthをStringのlengthとして、sourceLength + endとして扱われます。resultはString valueであり、String objectではありません。

これは呼び出されたとき、次のstepsを実行します:

  1. thisValuethis valueとする。
  2. RequireObjectCoercible(thisValue)を実行する。
  3. stringを ? ToString(thisValue) とする。
  4. lengthstringのlengthとする。
  5. intStartを ? ToIntegerOrInfinity(start) とする。
  6. intStart = -∞なら、fromを0とする。
  7. そうでなく、intStart < 0なら、frommax(length + intStart, 0)とする。
  8. そうでなければ、frommin(intStart, length)とする。
  9. endundefinedなら、intEndlengthとする;そうでなければ、intEndを ? ToIntegerOrInfinity(end) とする。
  10. intEnd = -∞なら、toを0とする。
  11. そうでなく、intEnd < 0なら、tomax(length + intEnd, 0)とする。
  12. そうでなければ、tomin(intEnd, length)とする。
  13. fromtoなら、empty Stringを返す。
  14. stringfromからtoまでのsubstringを返す。
Note

このmethodは意図的にgenericです;そのthis valueがString objectであることをrequireしません。したがって、methodとして使用するために他の種類のobjectsへtransferできます。

22.1.3.23 String.prototype.split ( separator, limit )

このmethodは、このobjectをStringへconvertしたresultのsubstringsが格納されたArrayを返します。substringsは、separatorのoccurrencesをleft to rightにsearchすることによってdetermineされます;これらのoccurrencesはreturned array内のいかなるStringのpartでもありませんが、String valueをdivide upする役割を果たします。separatorのvalueは任意のlengthのStringであってもよく、またはRegExpのように%Symbol.split% methodを持つobjectであってもよいです。

これは呼び出されたとき、次のstepsを実行します:

  1. thisValuethis valueとする。
  2. RequireObjectCoercible(thisValue)を実行する。
  3. separatorがObjectなら、
    1. splitterを ? GetMethod(separator, %Symbol.split%) とする。
    2. splitterundefinedでないなら、
      1. Call(splitter, separator, « thisValue, limit »)を返す。
  4. stringを ? ToString(thisValue) とする。
  5. limitundefinedなら、limを232 - 1とする;そうでなければ、lim(? ToUint32(limit))とする。
  6. separatorStringを ? ToString(separator) とする。
  7. lim = 0なら、
    1. CreateArrayFromList(« »)を返す。
  8. separatorundefinedなら、
    1. CreateArrayFromListstring »)を返す。
  9. separatorLengthseparatorStringのlengthとする。
  10. separatorLength = 0なら、
    1. stringLengthstringのlengthとする。
    2. outLengthlimを0とstringLengthの間にclampingしたresultとする。
    3. headstringの0からoutLengthまでのsubstringとする。
    4. codeUnitsを、headのelementsであるcode unitsのsequenceからなるListとする。
    5. CreateArrayFromList(codeUnits)を返す。
  11. stringがempty Stringなら、CreateArrayFromListstring »)を返す。
  12. substringsを新しい空のListとする。
  13. searchStartを0とする。
  14. matchIndexStringIndexOf(string, separatorString, 0)とする。
  15. matchIndexnot-foundでない間、繰り返す
    1. substringstringsearchStartからmatchIndexまでのsubstringとする。
    2. substringsubstringsへappendする。
    3. substrings内のelementsの数がlimなら、CreateArrayFromList(substrings)を返す。
    4. searchStartmatchIndex + separatorLengthに設定する。
    5. matchIndexStringIndexOf(string, separatorString, searchStart)に設定する。
  16. substringstringsearchStartからのsubstringとする。
  17. substringsubstringsへappendする。
  18. CreateArrayFromList(substrings)を返す。
Note 1

separatorのvalueはempty Stringであってもよいです。この場合、separatorはinput Stringのbeginningまたはendにあるempty substringにはmatchせず、previous separator matchのendにあるempty substringにもmatchしません。separatorがempty Stringである場合、Stringはindividual code unit elementsへsplit upされます;result arrayのlengthはStringのlengthに等しく、各substringはone code unitを含みます。

this valueがempty Stringである(またはそれへconvertsされる)場合、resultはseparatorがempty Stringにmatchできるかどうかに依存します。matchできる場合、result arrayはelementsを含みません。そうでなければ、result arrayはone elementを含み、それはempty Stringです。

separatorundefinedである場合、result arrayはthis value(Stringへconvertedされる)であるone Stringだけを含みます。limitundefinedでない場合、output arrayはlimit elements以下を含むようにtruncatedされます。

Note 2

このmethodは意図的にgenericです;そのthis valueがString objectであることをrequireしません。したがって、methodとして使用するために他の種類のobjectsへtransferできます。

22.1.3.24 String.prototype.startsWith ( searchString [ , position ] )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. thisValuethis valueとする。
  2. RequireObjectCoercible(thisValue)を実行する。
  3. stringを ? ToString(thisValue) とする。
  4. isRegexpを ? IsRegExp(searchString) とする。
  5. isRegexptrueなら、TypeError例外をthrowする。
  6. searchStringを ? ToString(searchString) に設定する。
  7. lengthstringのlengthとする。
  8. positionundefinedなら、positionを0に設定する;そうでなければ、positionを ? ToIntegerOrInfinity(position) に設定する。
  9. startpositionを0とlengthの間にclampingしたresultとする。
  10. searchLengthsearchStringのlengthとする。
  11. searchLength = 0なら、trueを返す。
  12. endstart + searchLengthとする。
  13. end > lengthなら、falseを返す。
  14. substringstringstartからendまでのsubstringとする。
  15. substringsearchStringなら、trueを返す。
  16. falseを返す。
Note 1

first argumentがRegExpである場合にexceptionをthrowすることは、そのようなargument valuesをallowするextensionsをfuture editionsがdefineできるようにするために指定されています。

Note 2

このmethodは意図的にgenericです;そのthis valueがString objectであることをrequireしません。したがって、methodとして使用するために他の種類のobjectsへtransferできます。

22.1.3.25 String.prototype.substring ( start, end )

このmethodは、このobjectをStringへconvertしたresultのsubstringを返します。これはindex startから始まり、Stringのindex endまで(ただしendを含まない)runningします(またはendundefinedならStringのendまで)。resultはString valueであり、String objectではありません。

いずれかのargumentがNaNまたはnegativeである場合、それはzeroで置き換えられます;いずれかのargumentがStringのlengthよりstrictly greaterである場合、それはStringのlengthで置き換えられます。

startendよりstrictly greaterである場合、それらはswappedされます。

これは呼び出されたとき、次のstepsを実行します:

  1. thisValuethis valueとする。
  2. RequireObjectCoercible(thisValue)を実行する。
  3. stringを ? ToString(thisValue) とする。
  4. lengthstringのlengthとする。
  5. intStartを ? ToIntegerOrInfinity(start) とする。
  6. endundefinedなら、intEndlengthとする;そうでなければ、intEndを ? ToIntegerOrInfinity(end) とする。
  7. finalStartintStartを0とlengthの間にclampingしたresultとする。
  8. finalEndintEndを0とlengthの間にclampingしたresultとする。
  9. frommin(finalStart, finalEnd)とする。
  10. tomax(finalStart, finalEnd)とする。
  11. stringfromからtoまでのsubstringを返す。
Note

このmethodは意図的にgenericです;そのthis valueがString objectであることをrequireしません。したがって、methodとして使用するために他の種類のobjectsへtransferできます。

22.1.3.26 String.prototype.toLocaleLowerCase ( [ reserved1 [ , reserved2 ] ] )

ECMA-402 Internationalization APIを含むECMAScript implementationは、このmethodをECMA-402 specificationで指定される通りにimplementしなければなりません。ECMAScript implementationがECMA-402 APIを含まない場合、このmethodの次のspecificationが使用されます:

このmethodは、6.1.4でdescribedされる通り、String valueをUTF-16 encoded code pointsのsequenceとしてinterpretします。

toLowerCaseとexactly the sameに動作しますが、host environmentのcurrent localeのconventionsに対応するlocale-sensitive resultをyieldすることを意図している点が異なります。regular Unicode case mappingsとそのlanguageのrulesがconflictする少数のcases(Turkishなど)にのみdifferenceが生じます。

このmethodのoptional parametersのmeaningはECMA-402 specificationで定義されます;ECMA-402 supportを含まないimplementationsは、それらのparameter positionsを他の目的に使用してはなりません。

Note

このmethodは意図的にgenericです;そのthis valueがString objectであることをrequireしません。したがって、methodとして使用するために他の種類のobjectsへtransferできます。

22.1.3.27 String.prototype.toLocaleUpperCase ( [ reserved1 [ , reserved2 ] ] )

ECMA-402 Internationalization APIを含むECMAScript implementationは、このmethodをECMA-402 specificationで指定される通りにimplementしなければなりません。ECMAScript implementationがECMA-402 APIを含まない場合、このmethodの次のspecificationが使用されます:

このmethodは、6.1.4でdescribedされる通り、String valueをUTF-16 encoded code pointsのsequenceとしてinterpretします。

toUpperCaseとexactly the sameに動作しますが、host environmentのcurrent localeのconventionsに対応するlocale-sensitive resultをyieldすることを意図している点が異なります。regular Unicode case mappingsとそのlanguageのrulesがconflictする少数のcases(Turkishなど)にのみdifferenceが生じます。

このmethodのoptional parametersのmeaningはECMA-402 specificationで定義されます;ECMA-402 supportを含まないimplementationsは、それらのparameter positionsを他の目的に使用してはなりません。

Note

このmethodは意図的にgenericです;そのthis valueがString objectであることをrequireしません。したがって、methodとして使用するために他の種類のobjectsへtransferできます。

22.1.3.28 String.prototype.toLowerCase ( )

このmethodは、6.1.4でdescribedされる通り、String valueをUTF-16 encoded code pointsのsequenceとしてinterpretします。

これは呼び出されたとき、次のstepsを実行します:

  1. thisValuethis valueとする。
  2. RequireObjectCoercible(thisValue)を実行する。
  3. stringを ? ToString(thisValue) とする。
  4. sTextStringToCodePoints(string)とする。
  5. lowerTextを、Unicode Default Case Conversion algorithmに従うtoLowercase(sText)とする。
  6. lowercaseStringCodePointsToString(lowerText)とする。
  7. lowercaseStringを返す。

resultは、Unicode Character Database内のlocale-insensitive case mappingsに従ってderivedされなければなりません(これは明示的にfile UnicodeData.txtだけでなく、それにaccompaniesするfile SpecialCasing.txt内のすべてのlocale-insensitive mappingsも含みます)。

Note 1

一部のcode pointsのcase mappingはmultiple code pointsをproduceする場合があります。この場合、result Stringはsource Stringとsame lengthでないことがあります。toUpperCasetoLowerCaseの両方がcontext-sensitive behaviourを持つため、methodsはsymmetricalではありません。言い換えると、s.toUpperCase().toLowerCase()は必ずしもs.toLowerCase()にequalではありません。

Note 2

このmethodは意図的にgenericです;そのthis valueがString objectであることをrequireしません。したがって、methodとして使用するために他の種類のobjectsへtransferできます。

22.1.3.29 String.prototype.toString ( )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. ThisStringValue(this value)を返す。
Note

String objectについて、このmethodはvalueOf methodとsame thingを返すことになります。

22.1.3.30 String.prototype.toUpperCase ( )

このmethodは、6.1.4でdescribedされる通り、String valueをUTF-16 encoded code pointsのsequenceとしてinterpretします。

StringがUnicode Default Case ConversionのtoUppercase algorithmを使用してmappedされる点を除き、String.prototype.toLowerCaseとexactly the same wayにbehaveします。

Note

このmethodは意図的にgenericです;そのthis valueがString objectであることをrequireしません。したがって、methodとして使用するために他の種類のobjectsへtransferできます。

22.1.3.31 String.prototype.toWellFormed ( )

このmethodは、surrogate pairのpartではないすべてのleading surrogatesおよびtrailing surrogatesがU+FFFD (REPLACEMENT CHARACTER)で置き換えられた、このobjectのString representationを返します。

これは呼び出されたとき、次のstepsを実行します:

  1. thisValuethis valueとする。
  2. RequireObjectCoercible(thisValue)を実行する。
  3. stringを ? ToString(thisValue) とする。
  4. stringLengthstringのlengthとする。
  5. kを0とする。
  6. resultをempty Stringとする。
  7. k < stringLengthの間、繰り返す
    1. codePointCodePointAt(string, k)とする。
    2. codePoint.[[IsUnpairedSurrogate]]trueなら、
      1. resultresultと0xFFFD (REPLACEMENT CHARACTER)のstring-concatenationに設定する。
    3. そうでなければ、
      1. resultresultUTF16EncodeCodePoint(codePoint.[[CodePoint]])のstring-concatenationに設定する。
    4. kk + codePoint.[[CodeUnitCount]]に設定する。
  8. resultを返す。

22.1.3.32 String.prototype.trim ( )

このmethodは、6.1.4でdescribedされる通り、String valueをUTF-16 encoded code pointsのsequenceとしてinterpretします。

これは呼び出されたとき、次のstepsを実行します:

  1. thisValuethis valueとする。
  2. TrimString(thisValue, start+end)を返す。
Note

このmethodは意図的にgenericです;そのthis valueがString objectであることをrequireしません。したがって、methodとして使用するために他の種類のobjectsへtransferできます。

22.1.3.32.1 TrimString ( arg, where )

The abstract operation TrimString takes arguments arg (an ECMAScript language value) and where (start, end, or start+end) and returns either a normal completion containing a String or a throw completion. 6.1.4でdescribedされる通り、argをUTF-16 encoded code pointsのsequenceとしてinterpretします。 It performs the following steps when called:

  1. RequireObjectCoercible(arg)を実行する。
  2. stringを ? ToString(arg) とする。
  3. wherestartなら、
    1. trimmedStringを、stringからleading white spaceがremovedされたcopyであるString valueとする。
  4. そうでなく、whereendなら、
    1. trimmedStringを、stringからtrailing white spaceがremovedされたcopyであるString valueとする。
  5. そうでなければ、
    1. Assert: wherestart+endである。
    2. trimmedStringを、stringからleadingおよびtrailing white spaceの両方がremovedされたcopyであるString valueとする。
  6. trimmedStringを返す。

white spaceのdefinitionはWhiteSpaceLineTerminatorのunionです。Unicode code pointがUnicode general category “Space_Separator” (“Zs”)に属するかどうかをdetermineするとき、code unit sequencesは6.1.4で指定される通り、UTF-16 encoded code point sequencesとしてinterpretedされます。

22.1.3.33 String.prototype.trimEnd ( )

このmethodは、6.1.4でdescribedされる通り、String valueをUTF-16 encoded code pointsのsequenceとしてinterpretします。

これは呼び出されたとき、次のstepsを実行します:

  1. stringthis valueとする。
  2. TrimString(string, end)を返す。
Note

このmethodは意図的にgenericです;そのthis valueがString objectであることをrequireしません。したがって、methodとして使用するために他の種類のobjectsへtransferできます。

22.1.3.34 String.prototype.trimStart ( )

このmethodは、6.1.4でdescribedされる通り、String valueをUTF-16 encoded code pointsのsequenceとしてinterpretします。

これは呼び出されたとき、次のstepsを実行します:

  1. stringthis valueとする。
  2. TrimString(string, start)を返す。
Note

このmethodは意図的にgenericです;そのthis valueがString objectであることをrequireしません。したがって、methodとして使用するために他の種類のobjectsへtransferできます。

22.1.3.35 String.prototype.valueOf ( )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. ThisStringValue(this value)を返す。

22.1.3.35.1 ThisStringValue ( arg )

The abstract operation ThisStringValue takes argument arg (an ECMAScript language value) and returns either a normal completion containing a String or a throw completion. It performs the following steps when called:

  1. argがStringなら、argを返す。
  2. argがObjectであり、かつarg[[StringData]] internal slotを持つなら、
    1. stringarg.[[StringData]]とする。
    2. Assert: stringはStringである。
    3. stringを返す。
  3. TypeError例外をThrowする。

22.1.3.36 String.prototype [ %Symbol.iterator% ] ( )

このmethodは、String valueのcode pointsをiterateし、各code pointをString valueとしてreturnするiterator objectを返します。

これは呼び出されたとき、次のstepsを実行します:

  1. stringthis valueとする。
  2. RequireObjectCoercible(string)を実行する。
  3. stringを ? ToString(string) に設定する。
  4. closureを、stringをcaptureし、呼び出されたとき次のstepsを実行する、parametersを持たない新しいAbstract Closureとする:
    1. lengthstringのlengthとする。
    2. positionを0とする。
    3. position < lengthの間、繰り返す
      1. codePointCodePointAt(string, position)とする。
      2. nextIndexposition + codePoint.[[CodeUnitCount]]とする。
      3. resultStringstringpositionからnextIndexまでのsubstringとする。
      4. positionnextIndexに設定する。
      5. GeneratorYield(CreateIteratorResultObject(resultString, false))を実行する。
    4. NormalCompletion(unused)を返す。
  5. CreateIteratorFromClosure(closure, "%StringIteratorPrototype%", %StringIteratorPrototype%)を返す。

このmethodの"name" propertyのvalueは"[Symbol.iterator]"です。

22.1.4 Properties of String Instances

String instancesはString exotic objectsであり、そのようなobjectsに対して指定されたinternal methodsを持ちます。String instancesはString prototype objectからpropertiesをinheritします。String instancesはまた[[StringData]] internal slotを持ちます。[[StringData]] internal slotは、このString objectによって表されるString valueです。

String instancesは"length" property、およびinteger-indexed namesを持つenumerable propertiesのsetを持ちます。

22.1.4.1 length

このString objectによって表されるString value内のelementsの数。

String objectがinitializeされると、このpropertyはunchangingです。これはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

22.1.5 String Iterator Objects

String Iteratorは、特定のString instance objectに対するspecific iterationを表すobjectです。String Iterator objectsにはnamed constructorは存在しません。代わりに、String Iterator objectsはString instance objectsの特定のmethodsを呼び出すことで作成されます。

22.1.5.1 The %StringIteratorPrototype% Object

%StringIteratorPrototype% objectは:

22.1.5.1.1 %StringIteratorPrototype%.next ( )

  1. GeneratorResume(this value, empty, "%StringIteratorPrototype%")を返す。

22.1.5.1.2 %StringIteratorPrototype% [ %Symbol.toStringTag% ]

%Symbol.toStringTag% propertyのinitial valueはString value "String Iterator"です。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }を持ちます。

22.2 RegExp(Regular Expression)Objects

RegExp objectはregular expressionおよびassociated flagsを含みます。

Note

regular expressionsのformおよびfunctionalityは、Perl 5 programming languageのregular expression facilityをmodelにしています。

22.2.1 Patterns

RegExp constructorは、input pattern Stringに対して以下のgrammarを適用します。grammarがStringをPatternのexpansionとしてinterpretできない場合、errorが発生します。

Syntax

Pattern[UnicodeMode, UnicodeSetsMode, NamedCaptureGroups] :: Disjunction[?UnicodeMode, ?UnicodeSetsMode, ?NamedCaptureGroups] Disjunction[UnicodeMode, UnicodeSetsMode, NamedCaptureGroups] :: Alternative[?UnicodeMode, ?UnicodeSetsMode, ?NamedCaptureGroups] Alternative[?UnicodeMode, ?UnicodeSetsMode, ?NamedCaptureGroups] | Disjunction[?UnicodeMode, ?UnicodeSetsMode, ?NamedCaptureGroups] Alternative[UnicodeMode, UnicodeSetsMode, NamedCaptureGroups] :: [empty] Alternative[?UnicodeMode, ?UnicodeSetsMode, ?NamedCaptureGroups] Term[?UnicodeMode, ?UnicodeSetsMode, ?NamedCaptureGroups] Term[UnicodeMode, UnicodeSetsMode, NamedCaptureGroups] :: Assertion[?UnicodeMode, ?UnicodeSetsMode, ?NamedCaptureGroups] Atom[?UnicodeMode, ?UnicodeSetsMode, ?NamedCaptureGroups] Atom[?UnicodeMode, ?UnicodeSetsMode, ?NamedCaptureGroups] Quantifier Assertion[UnicodeMode, UnicodeSetsMode, NamedCaptureGroups] :: ^ $ \b \B (?= Disjunction[?UnicodeMode, ?UnicodeSetsMode, ?NamedCaptureGroups] ) (?! Disjunction[?UnicodeMode, ?UnicodeSetsMode, ?NamedCaptureGroups] ) (?<= Disjunction[?UnicodeMode, ?UnicodeSetsMode, ?NamedCaptureGroups] ) (?<! Disjunction[?UnicodeMode, ?UnicodeSetsMode, ?NamedCaptureGroups] ) Quantifier :: QuantifierPrefix QuantifierPrefix ? QuantifierPrefix :: * + ? { DecimalDigits[~Sep] } { DecimalDigits[~Sep] ,} { DecimalDigits[~Sep] , DecimalDigits[~Sep] } Atom[UnicodeMode, UnicodeSetsMode, NamedCaptureGroups] :: PatternCharacter . \ AtomEscape[?UnicodeMode, ?NamedCaptureGroups] CharacterClass[?UnicodeMode, ?UnicodeSetsMode] ( GroupSpecifier[?UnicodeMode]opt Disjunction[?UnicodeMode, ?UnicodeSetsMode, ?NamedCaptureGroups] ) (? RegularExpressionModifiers : Disjunction[?UnicodeMode, ?UnicodeSetsMode, ?NamedCaptureGroups] ) (? RegularExpressionModifiers - RegularExpressionModifiers : Disjunction[?UnicodeMode, ?UnicodeSetsMode, ?NamedCaptureGroups] ) RegularExpressionModifiers :: [empty] RegularExpressionModifiers RegularExpressionModifier RegularExpressionModifier :: one of i m s SyntaxCharacter :: one of ^ $ \ . * + ? ( ) [ ] { } | PatternCharacter :: SourceCharacter but not SyntaxCharacter AtomEscape[UnicodeMode, NamedCaptureGroups] :: DecimalEscape CharacterClassEscape[?UnicodeMode] CharacterEscape[?UnicodeMode] [+NamedCaptureGroups] k GroupName[?UnicodeMode] CharacterEscape[UnicodeMode] :: ControlEscape c AsciiLetter 0 [lookahead ∉ DecimalDigit] HexEscapeSequence RegExpUnicodeEscapeSequence[?UnicodeMode] IdentityEscape[?UnicodeMode] ControlEscape :: one of f n r t v GroupSpecifier[UnicodeMode] :: ? GroupName[?UnicodeMode] GroupName[UnicodeMode] :: < RegExpIdentifierName[?UnicodeMode] > RegExpIdentifierName[UnicodeMode] :: RegExpIdentifierStart[?UnicodeMode] RegExpIdentifierName[?UnicodeMode] RegExpIdentifierPart[?UnicodeMode] RegExpIdentifierStart[UnicodeMode] :: IdentifierStartChar \ RegExpUnicodeEscapeSequence[+UnicodeMode] [~UnicodeMode] UnicodeLeadSurrogate UnicodeTrailSurrogate RegExpIdentifierPart[UnicodeMode] :: IdentifierPartChar \ RegExpUnicodeEscapeSequence[+UnicodeMode] [~UnicodeMode] UnicodeLeadSurrogate UnicodeTrailSurrogate RegExpUnicodeEscapeSequence[UnicodeMode] :: [+UnicodeMode] u HexLeadSurrogate \u HexTrailSurrogate [+UnicodeMode] u HexLeadSurrogate [+UnicodeMode] u HexTrailSurrogate [+UnicodeMode] u HexNonSurrogate [~UnicodeMode] u Hex4Digits [+UnicodeMode] u{ CodePoint } UnicodeLeadSurrogate :: any Unicode code point in the inclusive interval from U+D800 to U+DBFF UnicodeTrailSurrogate :: any Unicode code point in the inclusive interval from U+DC00 to U+DFFF

associatedするu HexLeadSurrogateのchoiceがambiguousである各\u HexTrailSurrogateは、そうでなければ対応する\u HexTrailSurrogateを持たない、nearest possibleなu HexLeadSurrogateにassociatedされなければなりません。

HexLeadSurrogate :: Hex4Digits but only if the MV of Hex4Digits is in the inclusive interval from 0xD800 to 0xDBFF HexTrailSurrogate :: Hex4Digits but only if the MV of Hex4Digits is in the inclusive interval from 0xDC00 to 0xDFFF HexNonSurrogate :: Hex4Digits but only if the MV of Hex4Digits is not in the inclusive interval from 0xD800 to 0xDFFF IdentityEscape[UnicodeMode] :: [+UnicodeMode] SyntaxCharacter [+UnicodeMode] / [~UnicodeMode] SourceCharacter but not UnicodeIDContinue DecimalEscape :: NonZeroDigit DecimalDigits[~Sep]opt [lookahead ∉ DecimalDigit] CharacterClassEscape[UnicodeMode] :: d D s S w W [+UnicodeMode] p{ UnicodePropertyValueExpression } [+UnicodeMode] P{ UnicodePropertyValueExpression } UnicodePropertyValueExpression :: UnicodePropertyName = UnicodePropertyValue LoneUnicodePropertyNameOrValue UnicodePropertyName :: UnicodePropertyNameCharacters UnicodePropertyNameCharacters :: UnicodePropertyNameCharacter UnicodePropertyNameCharactersopt UnicodePropertyValue :: UnicodePropertyValueCharacters LoneUnicodePropertyNameOrValue :: UnicodePropertyValueCharacters UnicodePropertyValueCharacters :: UnicodePropertyValueCharacter UnicodePropertyValueCharactersopt UnicodePropertyValueCharacter :: UnicodePropertyNameCharacter DecimalDigit UnicodePropertyNameCharacter :: AsciiLetter _ CharacterClass[UnicodeMode, UnicodeSetsMode] :: [ [lookahead ≠ ^] ClassContents[?UnicodeMode, ?UnicodeSetsMode] ] [^ ClassContents[?UnicodeMode, ?UnicodeSetsMode] ] ClassContents[UnicodeMode, UnicodeSetsMode] :: [empty] [~UnicodeSetsMode] NonemptyClassRanges[?UnicodeMode] [+UnicodeSetsMode] ClassSetExpression NonemptyClassRanges[UnicodeMode] :: ClassAtom[?UnicodeMode] ClassAtom[?UnicodeMode] NonemptyClassRangesNoDash[?UnicodeMode] ClassAtom[?UnicodeMode] - ClassAtom[?UnicodeMode] ClassContents[?UnicodeMode, ~UnicodeSetsMode] NonemptyClassRangesNoDash[UnicodeMode] :: ClassAtom[?UnicodeMode] ClassAtomNoDash[?UnicodeMode] NonemptyClassRangesNoDash[?UnicodeMode] ClassAtomNoDash[?UnicodeMode] - ClassAtom[?UnicodeMode] ClassContents[?UnicodeMode, ~UnicodeSetsMode] ClassAtom[UnicodeMode] :: - ClassAtomNoDash[?UnicodeMode] ClassAtomNoDash[UnicodeMode] :: SourceCharacter but not one of \ or ] or - \ ClassEscape[?UnicodeMode] ClassEscape[UnicodeMode] :: b [+UnicodeMode] - CharacterClassEscape[?UnicodeMode] CharacterEscape[?UnicodeMode] ClassSetExpression :: ClassUnion ClassIntersection ClassSubtraction ClassUnion :: ClassSetRange ClassUnionopt ClassSetOperand ClassUnionopt ClassIntersection :: ClassSetOperand && [lookahead ≠ &] ClassSetOperand ClassIntersection && [lookahead ≠ &] ClassSetOperand ClassSubtraction :: ClassSetOperand -- ClassSetOperand ClassSubtraction -- ClassSetOperand ClassSetRange :: ClassSetCharacter - ClassSetCharacter ClassSetOperand :: NestedClass ClassStringDisjunction ClassSetCharacter NestedClass :: [ [lookahead ≠ ^] ClassContents[+UnicodeMode, +UnicodeSetsMode] ] [^ ClassContents[+UnicodeMode, +UnicodeSetsMode] ] \ CharacterClassEscape[+UnicodeMode] Note 1

ここでの最初の2行はCharacterClassとequivalentです。

ClassStringDisjunction :: \q{ ClassStringDisjunctionContents } ClassStringDisjunctionContents :: ClassString ClassString | ClassStringDisjunctionContents ClassString :: [empty] NonEmptyClassString NonEmptyClassString :: ClassSetCharacter NonEmptyClassStringopt ClassSetCharacter :: [lookahead ∉ ClassSetReservedDoublePunctuator] SourceCharacter but not ClassSetSyntaxCharacter \ CharacterEscape[+UnicodeMode] \ ClassSetReservedPunctuator \b ClassSetReservedDoublePunctuator :: one of && !! ## $$ %% ** ++ ,, .. :: ;; << == >> ?? @@ ^^ `` ~~ ClassSetSyntaxCharacter :: one of ( ) [ ] { } / - \ | ClassSetReservedPunctuator :: one of & - ! # % , : ; < = > @ ` ~ Note 2

このsection内のいくつかのproductionsには、section B.1.2でalternative definitionsが与えられています。

22.2.1.1 Static Semantics: Early Errors

Note

このsectionはB.1.2.1でamendedされます。

Pattern :: Disjunction QuantifierPrefix :: { DecimalDigits , DecimalDigits } Atom :: (? RegularExpressionModifiers : Disjunction ) Atom :: (? RegularExpressionModifiers - RegularExpressionModifiers : Disjunction ) AtomEscape :: k GroupName AtomEscape :: DecimalEscape NonemptyClassRanges :: ClassAtom - ClassAtom ClassContents NonemptyClassRangesNoDash :: ClassAtomNoDash - ClassAtom ClassContents RegExpIdentifierStart :: \ RegExpUnicodeEscapeSequence RegExpIdentifierStart :: UnicodeLeadSurrogate UnicodeTrailSurrogate RegExpIdentifierPart :: \ RegExpUnicodeEscapeSequence RegExpIdentifierPart :: UnicodeLeadSurrogate UnicodeTrailSurrogate UnicodePropertyValueExpression :: UnicodePropertyName = UnicodePropertyValue
  • UnicodePropertyNameにmatchedするsource textが、Table 65の“Property name and aliases” columnにlistedされているUnicode property nameまたはproperty aliasでない場合、Syntax Errorです。
  • UnicodePropertyValueにmatchedするsource textが、UnicodePropertyNameにmatchedするsource textによって与えられるUnicode propertyまたはproperty aliasに対するproperty valueまたはproperty value aliasとして、PropertyValueAliases.txtにlistedされていない場合、Syntax Errorです。
UnicodePropertyValueExpression :: LoneUnicodePropertyNameOrValue
  • LoneUnicodePropertyNameOrValueにmatchedするsource textが、PropertyValueAliases.txtにlistedされているGeneral_Category (gc) propertyに対するUnicode property valueまたはproperty value aliasでもなく、Table 66の“Property name and aliases” columnにlistedされているbinary propertyまたはbinary property aliasでもなく、Table 67の“Property name” columnにlistedされているbinary property of stringsでもない場合、Syntax Errorです。
  • enclosing Pattern[UnicodeSetsMode] parameterを持たず、かつLoneUnicodePropertyNameOrValueにmatchedするsource textがTable 67の“Property name” columnにlistedされているbinary property of stringsである場合、Syntax Errorです。
CharacterClassEscape :: P{ UnicodePropertyValueExpression } CharacterClass :: [^ ClassContents ] NestedClass :: [^ ClassContents ] ClassSetRange :: ClassSetCharacter - ClassSetCharacter

22.2.1.2 Static Semantics: CountLeftCapturingParensWithin ( parseNode )

The abstract operation CountLeftCapturingParensWithin takes argument parseNode (a Parse Node) and returns a non-negative integer. parseNode内のleft-capturing parenthesesの数を返します。left-capturing parenthesisとは、 Atom :: ( GroupSpecifieropt Disjunction ) productionの( terminalにmatchedする任意の( pattern characterです。

Note

このsectionはB.1.2.2でamendedされます。

It performs the following steps when called:

  1. Assert: parseNodethe RegExp Pattern grammar内のproductionのinstanceである。
  2. parseNode内にcontainedされる Atom :: ( GroupSpecifieropt Disjunction ) Parse Nodesの数を返す。

22.2.1.3 Static Semantics: CountLeftCapturingParensBefore ( parseNode )

The abstract operation CountLeftCapturingParensBefore takes argument parseNode (a Parse Node) and returns a non-negative integer. enclosing pattern内でparseNodeの左側にoccurするleft-capturing parenthesesの数を返します。

Note

このsectionはB.1.2.2でamendedされます。

It performs the following steps when called:

  1. Assert: parseNodethe RegExp Pattern grammar内のproductionのinstanceである。
  2. patternparseNodeを含むPatternとする。
  3. pattern内にcontainedされる Atom :: ( GroupSpecifieropt Disjunction ) Parse Nodesのうち、parseNodeより前にoccurするかparseNodeをcontainするものの数を返す。

22.2.1.4 Static Semantics: MightBothParticipate ( x, y )

The abstract operation MightBothParticipate takes arguments x (a Parse Node) and y (a Parse Node) and returns a Boolean. It performs the following steps when called:

  1. Assert: xおよびyは同じenclosing Patternを持つ。
  2. enclosing Patternが、xAlternative内にcontainedされyがderived Disjunction内にcontainedされる、またはxがderived Disjunction内にcontainedされyAlternative内にcontainedされるような Disjunction :: Alternative | Disjunction Parse Nodeを含むなら、falseを返す。
  3. trueを返す。

22.2.1.5 Static Semantics: CapturingGroupNumber

The syntax-directed operation CapturingGroupNumber takes no arguments and returns a positive integer.

Note

このsectionはB.1.2.1でamendedされます。

It is defined piecewise over the following productions:

DecimalEscape :: NonZeroDigit
  1. NonZeroDigitのMVを返す。
DecimalEscape :: NonZeroDigit DecimalDigits
  1. nDecimalDigits内のcode pointsの数とする。
  2. NonZeroDigitのMV × 10n plus DecimalDigitsのMV)を返す。

“the MV of NonZeroDigit”および“the MV of DecimalDigits”のdefinitionsは12.9.3にあります。

22.2.1.6 Static Semantics: IsCharacterClass

The syntax-directed operation IsCharacterClass takes no arguments and returns a Boolean.

Note

このsectionはB.1.2.3でamendedされます。

It is defined piecewise over the following productions:

ClassAtom :: - ClassAtomNoDash :: SourceCharacter but not one of \ or ] or - ClassEscape :: b - CharacterEscape
  1. falseを返す。
ClassEscape :: CharacterClassEscape
  1. trueを返す。

22.2.1.7 Static Semantics: CharacterValue

The syntax-directed operation CharacterValue takes no arguments and returns a non-negative integer.

Note 1

このsectionはB.1.2.4でamendedされます。

It is defined piecewise over the following productions:

ClassAtom :: -
  1. U+002D (HYPHEN-MINUS)のnumeric valueを返す。
ClassAtomNoDash :: SourceCharacter but not one of \ or ] or -
  1. codePointSourceCharacterにmatchedするcode pointとする。
  2. codePointのnumeric valueを返す。
ClassEscape :: b
  1. U+0008 (BACKSPACE)のnumeric valueを返す。
ClassEscape :: -
  1. U+002D (HYPHEN-MINUS)のnumeric valueを返す。
CharacterEscape :: ControlEscape
  1. Table 63に従ったnumeric valueを返す。
Table 63: ControlEscape Code Point Values
ControlEscape Numeric Value Code Point Unicode Name Symbol
t 9 U+0009 CHARACTER TABULATION <HT>
n 10 U+000A LINE FEED (LF) <LF>
v 11 U+000B LINE TABULATION <VT>
f 12 U+000C FORM FEED (FF) <FF>
r 13 U+000D CARRIAGE RETURN (CR) <CR>
CharacterEscape :: c AsciiLetter
  1. codePointAsciiLetterにmatchedするcode pointとする。
  2. icodePointのnumeric valueとする。
  3. iを32で割ったremainderを返す。
CharacterEscape :: 0 [lookahead ∉ DecimalDigit]
  1. U+0000 (NULL)のnumeric valueを返す。
Note 2

\0は<NUL> characterを表し、decimal digitをfollowすることはできません。

CharacterEscape :: HexEscapeSequence
  1. HexEscapeSequenceのMVを返す。
RegExpUnicodeEscapeSequence :: u HexLeadSurrogate \u HexTrailSurrogate
  1. leadHexLeadSurrogateCharacterValueとする。
  2. trailHexTrailSurrogateCharacterValueとする。
  3. codePointUTF16SurrogatePairToCodePoint(lead, trail)とする。
  4. codePointのnumeric valueを返す。
RegExpUnicodeEscapeSequence :: u Hex4Digits
  1. Hex4DigitsのMVを返す。
RegExpUnicodeEscapeSequence :: u{ CodePoint }
  1. CodePointのMVを返す。
HexLeadSurrogate :: Hex4Digits HexTrailSurrogate :: Hex4Digits HexNonSurrogate :: Hex4Digits
  1. Hex4DigitsのMVを返す。
CharacterEscape :: IdentityEscape
  1. codePointIdentityEscapeにmatchedするcode pointとする。
  2. codePointのnumeric valueを返す。
ClassSetCharacter :: SourceCharacter but not ClassSetSyntaxCharacter
  1. codePointSourceCharacterにmatchedするcode pointとする。
  2. codePointのnumeric valueを返す。
ClassSetCharacter :: \ ClassSetReservedPunctuator
  1. codePointClassSetReservedPunctuatorにmatchedするcode pointとする。
  2. codePointのnumeric valueを返す。
ClassSetCharacter :: \b
  1. U+0008 (BACKSPACE)のnumeric valueを返す。

22.2.1.8 Static Semantics: MayContainStrings

The syntax-directed operation MayContainStrings takes no arguments and returns a Boolean. It is defined piecewise over the following productions:

CharacterClassEscape :: d D s S w W P{ UnicodePropertyValueExpression } UnicodePropertyValueExpression :: UnicodePropertyName = UnicodePropertyValue NestedClass :: [^ ClassContents ] ClassContents :: [empty] NonemptyClassRanges ClassSetOperand :: ClassSetCharacter
  1. falseを返す。
UnicodePropertyValueExpression :: LoneUnicodePropertyNameOrValue
  1. LoneUnicodePropertyNameOrValueにmatchedするsource textがTable 67の“Property name” columnにlistedされているbinary property of stringsであるなら、trueを返す。
  2. falseを返す。
ClassUnion :: ClassSetRange ClassUnionopt
  1. ClassUnionがpresentなら、ClassUnionMayContainStringsを返す。
  2. falseを返す。
ClassUnion :: ClassSetOperand ClassUnionopt
  1. ClassSetOperandMayContainStringstrueなら、trueを返す。
  2. ClassUnionがpresentなら、ClassUnionMayContainStringsを返す。
  3. falseを返す。
ClassIntersection :: ClassSetOperand && ClassSetOperand
  1. first ClassSetOperandMayContainStringsfalseなら、falseを返す。
  2. second ClassSetOperandMayContainStringsfalseなら、falseを返す。
  3. trueを返す。
ClassIntersection :: ClassIntersection && ClassSetOperand
  1. ClassIntersectionMayContainStringsfalseなら、falseを返す。
  2. ClassSetOperandMayContainStringsfalseなら、falseを返す。
  3. trueを返す。
ClassSubtraction :: ClassSetOperand -- ClassSetOperand
  1. first ClassSetOperandMayContainStringsを返す。
ClassSubtraction :: ClassSubtraction -- ClassSetOperand
  1. ClassSubtractionMayContainStringsを返す。
ClassStringDisjunctionContents :: ClassString | ClassStringDisjunctionContents
  1. ClassStringMayContainStringstrueなら、trueを返す。
  2. ClassStringDisjunctionContentsMayContainStringsを返す。
ClassString :: [empty]
  1. trueを返す。
ClassString :: NonEmptyClassString
  1. NonEmptyClassStringMayContainStringsを返す。
NonEmptyClassString :: ClassSetCharacter NonEmptyClassStringopt
  1. NonEmptyClassStringがpresentなら、trueを返す。
  2. falseを返す。

22.2.1.9 Static Semantics: GroupSpecifiersThatMatch ( thisGroupName )

The abstract operation GroupSpecifiersThatMatch takes argument thisGroupName (a GroupName Parse Node) and returns a List of GroupSpecifier Parse Nodes. It performs the following steps when called:

  1. namethisGroupNameCapturingGroupNameとする。
  2. patternthisGroupNameを含むPatternとする。
  3. resultを新しい空のListとする。
  4. patternが含む各GroupSpecifier groupSpecifierについて、以下を行う
    1. groupSpecifierCapturingGroupNamenameであるなら、
      1. groupSpecifierresultへappendする。
  5. resultを返す。

22.2.1.10 Static Semantics: CapturingGroupName

The syntax-directed operation CapturingGroupName takes no arguments and returns a String. It is defined piecewise over the following productions:

GroupName :: < RegExpIdentifierName >
  1. idTextUnescapedRegExpIdentifierNameRegExpIdentifierCodePointsとする。
  2. CodePointsToString(idTextUnescaped)を返す。

22.2.1.11 Static Semantics: RegExpIdentifierCodePoints

The syntax-directed operation RegExpIdentifierCodePoints takes no arguments and returns a List of code points. It is defined piecewise over the following productions:

RegExpIdentifierName :: RegExpIdentifierStart
  1. codePointRegExpIdentifierStartRegExpIdentifierCodePointとする。
  2. « codePoint »を返す。
RegExpIdentifierName :: RegExpIdentifierName RegExpIdentifierPart
  1. 派生したRegExpIdentifierNameRegExpIdentifierCodePointscodePointsとする。
  2. RegExpIdentifierPartRegExpIdentifierCodePointcodePointとする。
  3. codePointsと« codePoint »のlist-concatenationを返す。

22.2.1.12 Static Semantics: RegExpIdentifierCodePoint

The syntax-directed operation RegExpIdentifierCodePoint takes no arguments and returns a code point. It is defined piecewise over the following productions:

RegExpIdentifierStart :: IdentifierStartChar
  1. IdentifierStartCharにmatchedするcode pointを返す。
RegExpIdentifierPart :: IdentifierPartChar
  1. IdentifierPartCharにmatchedするcode pointを返す。
RegExpIdentifierStart :: \ RegExpUnicodeEscapeSequence RegExpIdentifierPart :: \ RegExpUnicodeEscapeSequence
  1. numeric valueがRegExpUnicodeEscapeSequenceCharacterValueであるcode pointを返す。
RegExpIdentifierStart :: UnicodeLeadSurrogate UnicodeTrailSurrogate RegExpIdentifierPart :: UnicodeLeadSurrogate UnicodeTrailSurrogate
  1. leadを、numeric valueがUnicodeLeadSurrogateにmatchedするcode pointのnumeric valueであるcode unitとする。
  2. trailを、numeric valueがUnicodeTrailSurrogateにmatchedするcode pointのnumeric valueであるcode unitとする。
  3. UTF16SurrogatePairToCodePoint(lead, trail)を返す。

22.2.2 Pattern Semantics

regular expression patternは、以下でdescribedされるprocessを使用してAbstract Closureへconvertedされます。implementationは、resultsがsameである限り、以下にlistedされたものよりefficientなalgorithmsを使用することがencouragedされます。Abstract ClosureはRegExp objectの[[RegExpMatcher]] internal slotのvalueとして使用されます。

Patternは、そのassociated flagsがuvも含まない場合はBMP patternです。そうでなければ、Unicode patternです。BMP patternは、Basic Multilingual Planeのrange内にあるUnicode code pointsである16-bit valuesのsequenceからなるものとしてinterpretedされるStringに対してmatchします。Unicode patternは、UTF-16を使用してencodedされたUnicode code pointsからなるものとしてinterpretedされるStringに対してmatchします。BMP patternのbehaviourをdescribeするcontextにおいて、“character”はsingle 16-bit Unicode BMP code pointを意味します。Unicode patternのbehaviourをdescribeするcontextにおいて、“character”はUTF-16 encoded code point(6.1.4)を意味します。いずれのcontextでも、“character value”は対応するnon-encoded code pointのnumeric valueを意味します。

Patternのsyntaxおよびsemanticsは、Patternのsource textがSourceCharacter valuesのListであり、各SourceCharacterがUnicode code pointに対応するものとして定義されます。BMP patternがnon-BMP SourceCharacterを含む場合、entire patternはUTF-16を使用してencodedされ、そのencodingのindividual code unitsがListのelementsとして使用されます。

Note

例えば、single non-BMP character U+1D11E(MUSICAL SYMBOL G CLEF)としてsource textでexpressedされたpatternを考えます。Unicode patternとしてinterpretedされる場合、それはsingle code point U+1D11Eからなるsingle element(character)Listになります。しかし、BMP patternとしてinterpretedされる場合、まずUTF-16 encodedされ、code units 0xD834および0xDD1Eからなるtwo element Listをproduceします。

Patternsは、non-BMP charactersがUTF-16 encodedされているECMAScript String valuesとしてRegExp constructorへpassedされます。例えば、single character MUSICAL SYMBOL G CLEF patternは、String valueとしてexpressedされる場合、elementsがcode units 0xD834および0xDD1Eであるlength 2のStringです。したがって、two pattern charactersからなるBMP patternとしてprocessするために、stringのさらなるtranslationは必要ありません。しかし、Unicode patternとしてprocessするには、sole elementがsingle pattern character、すなわちcode point U+1D11EであるListをproduceする際にUTF16SurrogatePairToCodePointを使用しなければなりません。

implementationは、UTF-16への、またはUTF-16からのそのようなtranslationsを実際にはperformしなくてもよいですが、このspecificationのsemanticsは、pattern matchingのresultがそのようなtranslationsがperformedされたかのようになることをrequireします。

22.2.2.1 Notation

以下のdescriptionsでは、次のinternal data structuresを使用します:

  • CharSetElementは、次の2つのentitiesのうちの1つです:
    • regexpRecord.[[UnicodeSets]]falseなら、CharSetElementは上記のPattern Semanticsの意味におけるcharacterです。
    • regexpRecord.[[UnicodeSets]]trueなら、CharSetElementは、elementsが上記のPattern Semanticsの意味におけるcharactersであるsequenceです。これにはempty sequence、one characterのsequence、およびmore than one characterのsequenceが含まれます。convenienceのため、このkindのCharSetElementsを扱うとき、individual characterはone characterのsequenceとinterchangeablyに扱われます。
  • CharSetは、CharSetElementsのmathematical setです。
  • CaptureRangeは、captureに含まれるcharactersのrangeを表すRecord { [[StartIndex]], [[EndIndex]] }です。ここで、[[StartIndex]]input内のrangeのstart index(inclusive)を表すintegerであり、[[EndIndex]]input内のrangeのend index(exclusive)を表すintegerです。任意のCaptureRangeについて、これらのindicesは[[StartIndex]][[EndIndex]]というinvariantをsatisfyしなければなりません。
  • MatchStateは、Record { [[Input]], [[EndIndex]], [[Captures]] }です。ここで、[[Input]]はmatch対象のStringを表すcharactersのList[[EndIndex]]integer[[Captures]]はpattern内の各left-capturing parenthesisに1つずつ対応するvaluesのListです。MatchStatesはregular expression matching algorithms内でpartial match statesを表すために使用されます。[[EndIndex]]は、patternによってこれまでmatchedされたlast input characterのindexに1を加えたものです。一方、[[Captures]]はcapturing parenthesesのresultsを保持します。[[Captures]]nth elementは、nth set of capturing parenthesesによってcapturedされたcharactersのrangeを表すCaptureRange、またはnth set of capturing parenthesesがまだreachedされていない場合はundefinedです。backtrackingにより、matching process中の任意の時点でmany MatchStatesが使用され得ます。
  • MatcherContinuationは、one MatchState argumentを受け取り、MatchStateまたはfailureのいずれかを返すAbstract Closureです。MatcherContinuationは、its captured valuesによってspecifiedされるpatternのremaining portionを、MatchState argumentでgivenされたintermediate stateからstartingして、inputに対してmatchしようとします。matchがsucceedsする場合、MatcherContinuationはreachedしたfinal MatchStateを返します;matchがfailsする場合、MatcherContinuationfailureを返します。
  • Matcherは、two arguments—MatchStateおよびMatcherContinuation—を受け取り、MatchStateまたはfailureのいずれかを返すAbstract Closureです。Matcherは、patternのmiddle subpattern(closureのcaptured valuesによってspecifiedされる)を、MatchState argumentでgivenされたintermediate stateからstartingして、MatchState[[Input]]に対してmatchしようとします。MatcherContinuation argumentは、patternのrestをmatchするclosureであるべきです。patternのsubpatternをmatchしてnew MatchStateをobtainした後、Matcherはそのnew MatchState上でMatcherContinuationをcallし、patternのrestもmatchできるかどうかをtestします。できる場合、MatcherMatcherContinuationによってreturnedされたMatchStateを返します;そうでない場合、Matcherはchoice pointsでdifferent choicesをtryしてもよく、succeedsするかすべてのpossibilitiesがexhaustedされるまでMatcherContinuationをrepeatedlyにcallします。

22.2.2.1.1 RegExp Records

RegExp Recordは、compilation中およびpossibly matching中に必要なRegExpに関するinformationをstoreするために使用されるRecord valueです。

これは次のfieldsを持ちます:

Table 64: RegExp Record Fields
Field Name Value Meaning
[[IgnoreCase]] a Boolean "i"がRegExpのflagsにappearsするかどうかを示す
[[Multiline]] a Boolean "m"がRegExpのflagsにappearsするかどうかを示す
[[DotAll]] a Boolean "s"がRegExpのflagsにappearsするかどうかを示す
[[Unicode]] a Boolean "u"がRegExpのflagsにappearsするかどうかを示す
[[UnicodeSets]] a Boolean "v"がRegExpのflagsにappearsするかどうかを示す
[[CapturingGroupsCount]] a non-negative integer RegExpのpattern内のleft-capturing parenthesesの数

22.2.2.2 Runtime Semantics: CompilePattern

The syntax-directed operation CompilePattern takes argument regexpRecord (a RegExp Record) and returns an Abstract Closure that takes a List of characters and a non-negative integer and returns either a MatchState or failure. It is defined piecewise over the following productions:

Pattern :: Disjunction
  1. mを、arguments regexpRecordおよびforwardを伴うDisjunctionCompileSubpatternとする。
  2. regexpRecordおよびmをcaptureし、calledされたときに次のstepsをperformする、parameters (input, index)を持つnew Abstract Closureを返す:
    1. Assert: inputはcharactersのListである。
    2. Assert: 0 ≤ indexinput内のelementsの数である。
    3. cを、nothingをcaptureし、calledされたときに次のstepsをperformする、parameters (y)を持つnew MatcherContinuationとする:
      1. Assert: yMatchStateである。
      2. yを返す。
    4. capabilityを、1からregexpRecord.[[CapturingGroupsCount]]までindexedされたregexpRecord.[[CapturingGroupsCount]]個のundefined valuesのListとする。
    5. xMatchState { [[Input]]: input, [[EndIndex]]: index, [[Captures]]: capability }とする。
    6. m(x, c)を返す。
Note

PatternはAbstract Closure valueへcompileされます。RegExpBuiltinExecは、このprocedureをcharactersのListおよびそのList内のoffsetにapplyして、patternがList内のexactlyそのoffsetからstartingしてmatchするかどうか、またmatchする場合はcapturing parenthesesのvaluesが何になるかをdetermineできます。22.2.2内のalgorithmsは、patternをcompileするとSyntaxError例外をthrowし得るようdesignedされています;一方で、patternがsuccessfully compiledされた後、resulting Abstract ClosureをapplyしてcharactersのList内のmatchをfindすることは、exceptionをthrowできません(out-of-memoryなど、どこでもoccurし得るimplementation-defined exceptionsを除く)。

22.2.2.3 Runtime Semantics: CompileSubpattern

The syntax-directed operation CompileSubpattern takes arguments regexpRecord (a RegExp Record) and direction (forward or backward) and returns a Matcher.

Note 1

このsectionはB.1.2.5でamendedされます。

It is defined piecewise over the following productions:

Disjunction :: Alternative | Disjunction
  1. m1を、arguments regexpRecordおよびdirectionを伴うAlternativeCompileSubpatternとする。
  2. m2を、arguments regexpRecordおよびdirectionを伴うDisjunctionCompileSubpatternとする。
  3. MatchTwoAlternatives(m1, m2)を返す。
Note 2

| regular expression operatorはtwo alternativesをseparateします。patternはまずleft Alternative(regular expressionのsequelがfollowする)をmatchしようとします;それがfailした場合、right Disjunction(regular expressionのsequelがfollowする)をmatchしようとします。left Alternative、right Disjunction、およびsequelがすべてchoice pointsを持つ場合、left Alternative内のnext choiceに移る前にsequel内のすべてのchoicesがtriedされます。left Alternative内のchoicesがexhaustedされると、left Alternativeの代わりにright Disjunctionがtriedされます。|によってskippedされたpatternのportion内のcapturing parenthesesは、Stringsではなくundefined valuesをproduceします。したがって、例えば、

/a|ab/.exec("abc")

"ab"ではなくresult "a"を返します。さらに、

/((a)|(ab))((c)|(bc))/.exec("abc")

はarray

["abc", "a", "a", undefined, "bc", undefined, "bc"]

を返し、

["abc", "ab", undefined, "ab", "c", "c", undefined]

ではありません。two alternativesがtriedされるorderはdirectionのvalueにindependentです。

Alternative :: [empty]
  1. EmptyMatcher()を返す。
Alternative :: Alternative Term
  1. m1を、arguments regexpRecordおよびdirectionを伴うAlternativeCompileSubpatternとする。
  2. m2を、arguments regexpRecordおよびdirectionを伴うTermCompileSubpatternとする。
  3. MatchSequence(m1, m2, direction)を返す。
Note 3

Consecutive Termsは、inputのconsecutive portionsをsimultaneouslyにmatchしようとします。directionforwardであるとき、left Alternative、right Term、およびregular expressionのsequelがすべてchoice pointsを持つ場合、right Term内のnext choiceへmoving onする前にsequel内のすべてのchoicesがtriedされ、left Alternative内のnext choiceへmoving onする前にright Term内のすべてのchoicesがtriedされます。directionbackwardであるとき、AlternativeおよびTermのevaluation orderはreversedされます。

Term :: Assertion
  1. argument regexpRecordを伴うAssertionCompileAssertionを返す。
Note 4

resulting Matcherdirectionにindependentです。

Term :: Atom
  1. arguments regexpRecordおよびdirectionを伴うAtomCompileAtomを返す。
Term :: Atom Quantifier
  1. mを、arguments regexpRecordおよびdirectionを伴うAtomCompileAtomとする。
  2. qQuantifierCompileQuantifierとする。
  3. Assert: q.[[Min]]q.[[Max]]である。
  4. parenIndexCountLeftCapturingParensBefore(Term)とする。
  5. parenCountCountLeftCapturingParensWithin(Atom)とする。
  6. mqparenIndex、およびparenCountをcaptureし、calledされたときに次のstepsをperformする、parameters (x, c)を持つnew Matcherを返す:
    1. Assert: xMatchStateである。
    2. Assert: cMatcherContinuationである。
    3. RepeatMatcher(m, q.[[Min]], q.[[Max]], q.[[Greedy]], x, c, parenIndex, parenCount)を返す。

22.2.2.3.1 RepeatMatcher ( m, min, max, greedy, matchState, continue, parenIndex, parenCount )

The abstract operation RepeatMatcher takes arguments m (a Matcher), min (a non-negative integer), max (a non-negative integer or +∞), greedy (a Boolean), matchState (a MatchState), continue (a MatcherContinuation), parenIndex (a non-negative integer), and parenCount (a non-negative integer) and returns either a MatchState or failure. It performs the following steps when called:

  1. max = 0なら、continue(matchState)を返す。
  2. dを、mminmaxgreedymatchStatecontinueparenIndex、およびparenCountをcaptureし、calledされたときに次のstepsをperformする、parameters (y)を持つnew MatcherContinuationとする:
    1. Assert: yMatchStateである。
    2. min = 0かつy.[[EndIndex]] = matchState.[[EndIndex]]なら、failureを返す。
    3. min = 0なら、min2を0とする;そうでなければ、min2min - 1とする。
    4. max = +∞なら、max2を+∞とする;そうでなければ、max2max - 1とする。
    5. RepeatMatcher(m, min2, max2, greedy, y, continue, parenIndex, parenCount)を返す。
  3. capabilitymatchState.[[Captures]]のcopyとする。
  4. parenIndex + 1からparenIndex + parenCountまでのinclusive interval内の各integer kについて、capability[k]をundefinedに設定する。
  5. inputmatchState.[[Input]]とする。
  6. ematchState.[[EndIndex]]とする。
  7. xrMatchState { [[Input]]: input, [[EndIndex]]: e, [[Captures]]: capability }とする。
  8. min ≠ 0なら、m(xr, d)を返す。
  9. greedyfalseなら、
    1. zcontinue(matchState)とする。
    2. zfailureでないなら、zを返す。
    3. m(xr, d)を返す。
  10. zm(xr, d)とする。
  11. zfailureでないなら、zを返す。
  12. continue(matchState)を返す。
Note 1

QuantifierがfollowするAtomは、Quantifierによってspecifiedされたnumber of timesだけrepeatedされます。Quantifierはnon-greedyであることができ、その場合、Atom patternはsequelをstill matchingしながら可能な限りfew times repeatedされます。またはgreedyであることができ、その場合、Atom patternはsequelをstill matchingしながら可能な限りmany times repeatedされます。Atom patternは、それがmatchするinput character sequenceではなくrepeatedされるため、Atomのdifferent repetitionsはdifferent input substringsにmatchし得ます。

Note 2

Atomとregular expressionのsequelがすべてchoice pointsを持つ場合、Atomはまず可能な限りmany(またはnon-greedyならfew)times matchedされます。last repetition of Atom内のnext choiceへmoving onする前に、sequel内のすべてのchoicesがtriedされます。Atomのlast(nth)repetition内のすべてのchoicesは、Atomのnext-to-last(n - 1)st repetition内のnext choiceへmoving onする前にtriedされます;その時点で、Atomのmore or fewer repetitionsが今やpossibleであることが判明する場合があります;これらは(again, possibleな限りfewまたはmanyからstartingして)exhaustedされ、その後、Atomの(n - 1)st repetition内のnext choiceへmoving onし、以降も同様です。

Compare

/a[a-z]{2,4}/.exec("abcdefghi")

これは"abcde"を返します。これに対して、

/a[a-z]{2,4}?/.exec("abcdefghi")

"abc"を返します。

さらに次を考えます:

/(aa|aabaac|ba|b|c)*/.exec("aabaac")

これは、aboveのchoice point orderingにより、array

["aaba", "ba"]

を返し、次のいずれでもありません:

["aabaac", "aabaac"]
["aabaac", "c"]

上記のchoice pointsのorderingは、two numbers(unary notationでrepresented)のgreatest common divisorをcalculateするregular expressionを書くために使用できます。次のexampleは10と15のgcdをcalculateします:

"aaaaaaaaaa,aaaaaaaaaaaaaaa".replace(/^(a+)\1*,\1+$/, "$1")

これはunary notationでgcd "aaaaa"を返します。

Note 3

RepeatMatcherのstep 4は、AtomがrepeatedされるたびにAtomのcapturesをclearします。そのbehaviourはregular expression

/(z)((a+)?(b+)?(c))*/.exec("zaacbbbcac")

で見ることができ、これはarray

["zaacbbbcac", "z", "ac", "a", undefined, "c"]

を返し、

["zaacbbbcac", "z", "ac", "a", "bbb", "c"]

ではありません。なぜなら、outermost *の各iterationが、quantified Atom内にcontainedされるすべてのcaptured Stringsをclearし、このcaseではcapture Strings numbered 2, 3, 4, and 5を含むためです。

Note 4

RepeatMatcherのstep 2.bは、minimum number of repetitionsがsatisfiedされた後、empty character sequenceにmatchするAtomのmore expansionsはfurther repetitionsとしてconsideredされないことを述べています。これはregular expression engineが次のようなpatternsでinfinite loopにfalling intoすることをpreventします:

/(a*)*/.exec("b")

または少しmore complicatedな:

/(a*)b\1+/.exec("baaaac")

これはarray

["b", ""]

を返します。

22.2.2.3.2 EmptyMatcher ( )

The abstract operation EmptyMatcher takes no arguments and returns a Matcher. It performs the following steps when called:

  1. nothingをcaptureし、calledされたときに次のstepsをperformする、parameters (matchState, continue)を持つnew Matcherを返す:
    1. Assert: matchStateMatchStateである。
    2. Assert: continueMatcherContinuationである。
    3. continue(matchState)を返す。

22.2.2.3.3 MatchTwoAlternatives ( m1, m2 )

The abstract operation MatchTwoAlternatives takes arguments m1 (a Matcher) and m2 (a Matcher) and returns a Matcher. It performs the following steps when called:

  1. m1およびm2をcaptureし、calledされたときに次のstepsをperformする、parameters (matchState, continue)を持つnew Matcherを返す:
    1. Assert: matchStateMatchStateである。
    2. Assert: continueMatcherContinuationである。
    3. resultm1(matchState, continue)とする。
    4. resultfailureでないなら、resultを返す。
    5. m2(matchState, continue)を返す。

22.2.2.3.4 MatchSequence ( m1, m2, direction )

The abstract operation MatchSequence takes arguments m1 (a Matcher), m2 (a Matcher), and direction (forward or backward) and returns a Matcher. It performs the following steps when called:

  1. directionforwardなら、
    1. m1およびm2をcaptureし、calledされたときに次のstepsをperformする、parameters (matchState, continue)を持つnew Matcherを返す:
      1. Assert: matchStateMatchStateである。
      2. Assert: continueMatcherContinuationである。
      3. dを、continueおよびm2をcaptureし、calledされたときに次のstepsをperformする、parameters (y)を持つnew MatcherContinuationとする:
        1. Assert: yMatchStateである。
        2. m2(y, continue)を返す。
      4. m1(matchState, d)を返す。
  2. Assert: directionbackwardである。
  3. m1およびm2をcaptureし、calledされたときに次のstepsをperformする、parameters (matchState, continue)を持つnew Matcherを返す:
    1. Assert: matchStateMatchStateである。
    2. Assert: continueMatcherContinuationである。
    3. dを、continueおよびm1をcaptureし、calledされたときに次のstepsをperformする、parameters (y)を持つnew MatcherContinuationとする:
      1. Assert: yMatchStateである。
      2. m1(y, continue)を返す。
    4. m2(matchState, d)を返す。

22.2.2.4 Runtime Semantics: CompileAssertion

The syntax-directed operation CompileAssertion takes argument regexpRecord (a RegExp Record) and returns a Matcher.

Note 1

このsectionはB.1.2.6でamendedされます。

It is defined piecewise over the following productions:

Assertion :: ^
  1. regexpRecordをcaptureし、calledされたときに次のstepsをperformする、parameters (matchState, continue)を持つnew Matcherを返す:
    1. Assert: matchStateMatchStateである。
    2. Assert: continueMatcherContinuationである。
    3. inputmatchState.[[Input]]とする。
    4. ematchState.[[EndIndex]]とする。
    5. e = 0である、またはregexpRecord.[[Multiline]]trueでありcharacter input[e - 1]がLineTerminatorによってmatchedされるなら、
      1. continue(matchState)を返す。
    6. failureを返す。
Note 2

y flagがpatternとともに使用される場合であっても、^は常にinputのbeginning、または(regexpRecord.[[Multiline]]trueなら)lineのbeginningにのみmatchします。

Assertion :: $
  1. regexpRecordをcaptureし、calledされたときに次のstepsをperformする、parameters (matchState, continue)を持つnew Matcherを返す:
    1. Assert: matchStateMatchStateである。
    2. Assert: continueMatcherContinuationである。
    3. inputmatchState.[[Input]]とする。
    4. ematchState.[[EndIndex]]とする。
    5. inputLengthinput内のelementsの数とする。
    6. e = inputLengthである、またはregexpRecord.[[Multiline]]trueでありcharacter input[e]がLineTerminatorによってmatchedされるなら、
      1. continue(matchState)を返す。
    7. failureを返す。
Assertion :: \b
  1. regexpRecordをcaptureし、calledされたときに次のstepsをperformする、parameters (matchState, continue)を持つnew Matcherを返す:
    1. Assert: matchStateMatchStateである。
    2. Assert: continueMatcherContinuationである。
    3. inputmatchState.[[Input]]とする。
    4. ematchState.[[EndIndex]]とする。
    5. aIsWordChar(regexpRecord, input, e - 1)とする。
    6. bIsWordChar(regexpRecord, input, e)とする。
    7. atrueでありbfalseである、またはafalseでありbtrueであるなら、continue(matchState)を返す。
    8. failureを返す。
Assertion :: \B
  1. regexpRecordをcaptureし、calledされたときに次のstepsをperformする、parameters (matchState, continue)を持つnew Matcherを返す:
    1. Assert: matchStateMatchStateである。
    2. Assert: continueMatcherContinuationである。
    3. inputmatchState.[[Input]]とする。
    4. ematchState.[[EndIndex]]とする。
    5. aIsWordChar(regexpRecord, input, e - 1)とする。
    6. bIsWordChar(regexpRecord, input, e)とする。
    7. atrueでありbtrueである、またはafalseでありbfalseであるなら、continue(matchState)を返す。
    8. failureを返す。
Assertion :: (?= Disjunction )
  1. mを、arguments regexpRecordおよびforwardを伴うDisjunctionCompileSubpatternとする。
  2. mをcaptureし、calledされたときに次のstepsをperformする、parameters (matchState, continue)を持つnew Matcherを返す:
    1. Assert: matchStateMatchStateである。
    2. Assert: continueMatcherContinuationである。
    3. dを、nothingをcaptureし、calledされたときに次のstepsをperformする、parameters (y)を持つnew MatcherContinuationとする:
      1. Assert: yMatchStateである。
      2. yを返す。
    4. resultm(matchState, d)とする。
    5. resultfailureなら、failureを返す。
    6. Assert: resultMatchStateである。
    7. capabilityresult.[[Captures]]とする。
    8. inputmatchState.[[Input]]とする。
    9. xematchState.[[EndIndex]]とする。
    10. zMatchState { [[Input]]: input, [[EndIndex]]: xe, [[Captures]]: capability }とする。
    11. continue(z)を返す。
Note 3

form (?= Disjunction )はzero-width positive lookaheadをspecifyします。succeedするには、Disjunction内のpatternがcurrent positionでmatchしなければなりませんが、sequelをmatchingする前にcurrent positionはadvancedされません。Disjunctionがcurrent positionでseveral waysにmatchできる場合、first oneのみがtriedされます。他のregular expression operatorsとは異なり、(?= formへのbacktrackingはありません(このunusual behaviourはPerlからinheritedされています)。これは、Disjunctionがcapturing parenthesesを含み、かつpatternのsequelがそれらのcapturesへのbackreferencesを含む場合にのみmatterします。

例えば、

/(?=(a+))/.exec("baaabac")

はfirst bの直後のempty Stringにmatchし、したがってarrayを返します:

["", "aaa"]

lookaheadへのbacktrackingがないことをillustrateするため、次を考えます:

/(?=(a+))a*b\1/.exec("baaabac")

このexpressionは

["aba", "a"]

を返し、次ではありません:

["aaaba", "a"]
Assertion :: (?! Disjunction )
  1. mを、arguments regexpRecordおよびforwardを伴うDisjunctionCompileSubpatternとする。
  2. mをcaptureし、calledされたときに次のstepsをperformする、parameters (matchState, continue)を持つnew Matcherを返す:
    1. Assert: matchStateMatchStateである。
    2. Assert: continueMatcherContinuationである。
    3. dを、nothingをcaptureし、calledされたときに次のstepsをperformする、parameters (y)を持つnew MatcherContinuationとする:
      1. Assert: yMatchStateである。
      2. yを返す。
    4. resultm(matchState, d)とする。
    5. resultfailureでないなら、failureを返す。
    6. continue(matchState)を返す。
Note 4

form (?! Disjunction )はzero-width negative lookaheadをspecifyします。succeedするには、Disjunction内のpatternがcurrent positionでmatchにfailしなければなりません。sequelをmatchingする前にcurrent positionはadvancedされません。Disjunctionはcapturing parenthesesを含むことができますが、それらへのbackreferencesはDisjunction自体の内側からのみ意味を持ちます。pattern内の他の場所からこれらのcapturing parenthesesへのbackreferencesは、negative lookaheadがpatternをsucceedさせるためにfailしなければならないため、常にundefinedを返します。例えば、

/(.*?)a(?!(a+)b\2c)\2(.*)/.exec("baaabaac")

は、some positive number n of a's、b、another n a's(first \2でspecified)、およびcがimmediately followedしないaを探します。second \2はnegative lookaheadの外側にあるため、undefinedに対してmatchesし、したがって常にsucceedsします。whole expressionはarrayを返します:

["baaabaac", "ba", undefined, "abaac"]
Assertion :: (?<= Disjunction )
  1. mを、arguments regexpRecordおよびbackwardを伴うDisjunctionCompileSubpatternとする。
  2. mをcaptureし、calledされたときに次のstepsをperformする、parameters (matchState, continue)を持つnew Matcherを返す:
    1. Assert: matchStateMatchStateである。
    2. Assert: continueMatcherContinuationである。
    3. dを、nothingをcaptureし、calledされたときに次のstepsをperformする、parameters (y)を持つnew MatcherContinuationとする:
      1. Assert: yMatchStateである。
      2. yを返す。
    4. resultm(matchState, d)とする。
    5. resultfailureなら、failureを返す。
    6. Assert: resultMatchStateである。
    7. capabilityresult.[[Captures]]とする。
    8. inputmatchState.[[Input]]とする。
    9. xematchState.[[EndIndex]]とする。
    10. zMatchState { [[Input]]: input, [[EndIndex]]: xe, [[Captures]]: capability }とする。
    11. continue(z)を返す。
Assertion :: (?<! Disjunction )
  1. mを、arguments regexpRecordおよびbackwardを伴うDisjunctionCompileSubpatternとする。
  2. mをcaptureし、calledされたときに次のstepsをperformする、parameters (matchState, continue)を持つnew Matcherを返す:
    1. Assert: matchStateMatchStateである。
    2. Assert: continueMatcherContinuationである。
    3. dを、nothingをcaptureし、calledされたときに次のstepsをperformする、parameters (y)を持つnew MatcherContinuationとする:
      1. Assert: yMatchStateである。
      2. yを返す。
    4. resultm(matchState, d)とする。
    5. resultfailureでないなら、failureを返す。
    6. continue(matchState)を返す。

22.2.2.4.1 IsWordChar ( regexpRecord, input, e )

The abstract operation IsWordChar takes arguments regexpRecord (a RegExp Record), input (a List of characters), and e (an integer) and returns a Boolean. It performs the following steps when called:

  1. inputLengthinput内のelementsの数とする。
  2. e = -1またはe = inputLengthなら、falseを返す。
  3. charをcharacter input[e]とする。
  4. WordCharacters(regexpRecord)がcharを含むなら、trueを返す。
  5. falseを返す。

22.2.2.5 Runtime Semantics: CompileQuantifier

The syntax-directed operation CompileQuantifier takes no arguments and returns a Record with fields [[Min]] (a non-negative integer), [[Max]] (a non-negative integer or +∞), and [[Greedy]] (a Boolean). It is defined piecewise over the following productions:

Quantifier :: QuantifierPrefix
  1. qpQuantifierPrefixCompileQuantifierPrefixとする。
  2. Record { [[Min]]: qp.[[Min]], [[Max]]: qp.[[Max]], [[Greedy]]: true }を返す。
Quantifier :: QuantifierPrefix ?
  1. qpQuantifierPrefixCompileQuantifierPrefixとする。
  2. Record { [[Min]]: qp.[[Min]], [[Max]]: qp.[[Max]], [[Greedy]]: false }を返す。

22.2.2.6 Runtime Semantics: CompileQuantifierPrefix

The syntax-directed operation CompileQuantifierPrefix takes no arguments and returns a Record with fields [[Min]] (a non-negative integer) and [[Max]] (a non-negative integer or +∞). It is defined piecewise over the following productions:

QuantifierPrefix :: *
  1. Record { [[Min]]: 0, [[Max]]: +∞ }を返す。
QuantifierPrefix :: +
  1. Record { [[Min]]: 1, [[Max]]: +∞ }を返す。
QuantifierPrefix :: ?
  1. Record { [[Min]]: 0, [[Max]]: 1 }を返す。
QuantifierPrefix :: { DecimalDigits }
  1. iDecimalDigitsのMVとする(12.9.3を参照)。
  2. Record { [[Min]]: i, [[Max]]: i }を返す。
QuantifierPrefix :: { DecimalDigits ,}
  1. iDecimalDigitsのMVとする。
  2. Record { [[Min]]: i, [[Max]]: +∞ }を返す。
QuantifierPrefix :: { DecimalDigits , DecimalDigits }
  1. iをfirst DecimalDigitsのMVとする。
  2. jをsecond DecimalDigitsのMVとする。
  3. Record { [[Min]]: i, [[Max]]: j }を返す。

22.2.2.7 Runtime Semantics: CompileAtom

The syntax-directed operation CompileAtom takes arguments regexpRecord (a RegExp Record) and direction (forward or backward) and returns a Matcher.

Note 1

このsectionはB.1.2.7でamendedされます。

It is defined piecewise over the following productions:

Atom :: PatternCharacter
  1. charPatternCharacterにmatchedするcharacterとする。
  2. charSetをcharacter charを含むone-element CharSetとする。
  3. CharacterSetMatcher(regexpRecord, charSet, false, direction)を返す。
Atom :: .
  1. charSetAllCharacters(regexpRecord)とする。
  2. regexpRecord.[[DotAll]]trueでないなら、
    1. LineTerminator productionのright-hand side上のcode pointに対応するすべてのcharactersをcharSetからremoveする。
  3. CharacterSetMatcher(regexpRecord, charSet, false, direction)を返す。
Atom :: CharacterClass
  1. ccをargument regexpRecordを伴うCharacterClassCompileCharacterClassとする。
  2. cscc.[[CharSet]]とする。
  3. regexpRecord.[[UnicodeSets]]falseである、またはcsのすべてのCharSetElementがsingle characterからなる(csがemptyの場合を含む)なら、CharacterSetMatcher(regexpRecord, cs, cc.[[Invert]], direction)を返す。
  4. Assert: cc.[[Invert]]falseである。
  5. listOfMatchersMatchersのempty Listとする。
  6. cs内のmore than 1 characterを含む各CharSetElement sについて、lengthのdescending orderでiteratingして、以下を行う
    1. cs2sのlast code pointを含むone-element CharSetとする。
    2. m2CharacterSetMatcher(regexpRecord, cs2, false, direction)とする。
    3. s内の各code point c1について、そのsecond-to-last code pointからbackwardsにiteratingして、以下を行う
      1. cs1c1を含むone-element CharSetとする。
      2. m1CharacterSetMatcher(regexpRecord, cs1, false, direction)とする。
      3. m2MatchSequence(m1, m2, direction)に設定する。
    4. m2listOfMatchersへappendする。
  7. singlesを、single characterからなるcsのすべてのCharSetElementを含むCharSetとする。
  8. CharacterSetMatcher(regexpRecord, singles, false, direction)をlistOfMatchersへappendする。
  9. csがcharactersのempty sequenceを含むなら、EmptyMatcher()をlistOfMatchersへappendする。
  10. m2listOfMatchers内のlast Matcherとする。
  11. listOfMatchersの各Matcher m1について、そのsecond-to-last elementからbackwardsにiteratingして、以下を行う
    1. m2MatchTwoAlternatives(m1, m2)に設定する。
  12. m2を返す。
Atom :: ( GroupSpecifieropt Disjunction )
  1. mを、arguments regexpRecordおよびdirectionを伴うDisjunctionCompileSubpatternとする。
  2. parenIndexCountLeftCapturingParensBefore(Atom)とする。
  3. directionm、およびparenIndexをcaptureし、calledされたときに次のstepsをperformする、parameters (x, c)を持つnew Matcherを返す:
    1. Assert: xMatchStateである。
    2. Assert: cMatcherContinuationである。
    3. dを、xcdirection、およびparenIndexをcaptureし、calledされたときに次のstepsをperformする、parameters (y)を持つnew MatcherContinuationとする:
      1. Assert: yMatchStateである。
      2. capabilityy.[[Captures]]のcopyとする。
      3. inputx.[[Input]]とする。
      4. xex.[[EndIndex]]とする。
      5. yey.[[EndIndex]]とする。
      6. directionforwardなら、
        1. Assert: xeyeである。
        2. rCaptureRange { [[StartIndex]]: xe, [[EndIndex]]: ye }とする。
      7. そうでなければ、
        1. Assert: directionbackwardである。
        2. Assert: yexeである。
        3. rCaptureRange { [[StartIndex]]: ye, [[EndIndex]]: xe }とする。
      8. capability[parenIndex + 1]をrに設定する。
      9. zMatchState { [[Input]]: input, [[EndIndex]]: ye, [[Captures]]: capability }とする。
      10. c(z)を返す。
    4. m(x, d)を返す。
Note 2

form ( Disjunction )のparenthesesは、Disjunction patternのcomponentsをgroup togetherすることと、matchのresultをsaveすることの両方にserveします。resultは、backreference(\ followed by a non-zero decimal number)で使用されたり、replace Stringでreferencedされたり、regular expression matching Abstract Closureからarrayのpartとしてreturnedされたりできます。parenthesesのcapturing behaviourをinhibitするには、代わりにform (?: Disjunction )を使用します。

Atom :: (? RegularExpressionModifiers : Disjunction )
  1. addModifiersRegularExpressionModifiersにmatchedするsource textとする。
  2. removeModifiersをempty Stringとする。
  3. modifiedRerUpdateModifiers(regexpRecord, CodePointsToString(addModifiers), removeModifiers)とする。
  4. arguments modifiedRerおよびdirectionを伴うDisjunctionCompileSubpatternを返す。
Atom :: (? RegularExpressionModifiers - RegularExpressionModifiers : Disjunction )
  1. addModifiersをfirst RegularExpressionModifiersにmatchedするsource textとする。
  2. removeModifiersをsecond RegularExpressionModifiersにmatchedするsource textとする。
  3. modifiedRerUpdateModifiers(regexpRecord, CodePointsToString(addModifiers), CodePointsToString(removeModifiers))とする。
  4. arguments modifiedRerおよびdirectionを伴うDisjunctionCompileSubpatternを返す。
AtomEscape :: DecimalEscape
  1. nDecimalEscapeCapturingGroupNumberとする。
  2. Assert: nregexpRecord.[[CapturingGroupsCount]]である。
  3. BackreferenceMatcher(regexpRecord, « n », direction)を返す。
Note 3

\ followed by a non-zero decimal number nというformのescape sequenceは、nth set of capturing parentheses(22.2.2.1)のresultにmatchします。regular expressionがn個未満のcapturing parenthesesを持つ場合、errorになります。regular expressionがn個以上のcapturing parenthesesを持つが、nth oneが何もcapturedしていないためundefinedである場合、backreferenceは常にsucceedsします。

AtomEscape :: CharacterEscape
  1. charValueCharacterEscapeCharacterValueとする。
  2. charをcharacter valueがcharValueであるcharacterとする。
  3. charSetをcharacter charを含むone-element CharSetとする。
  4. CharacterSetMatcher(regexpRecord, charSet, false, direction)を返す。
AtomEscape :: CharacterClassEscape
  1. csをargument regexpRecordを伴うCharacterClassEscapeCompileToCharSetとする。
  2. regexpRecord.[[UnicodeSets]]falseである、またはcsのすべてのCharSetElementがsingle characterからなる(csがemptyの場合を含む)なら、CharacterSetMatcher(regexpRecord, cs, false, direction)を返す。
  3. listOfMatchersMatchersのempty Listとする。
  4. cs内のmore than 1 characterを含む各CharSetElement sについて、lengthのdescending orderでiteratingして、以下を行う
    1. cs2sのlast code pointを含むone-element CharSetとする。
    2. m2CharacterSetMatcher(regexpRecord, cs2, false, direction)とする。
    3. s内の各code point c1について、そのsecond-to-last code pointからbackwardsにiteratingして、以下を行う
      1. cs1c1を含むone-element CharSetとする。
      2. m1CharacterSetMatcher(regexpRecord, cs1, false, direction)とする。
      3. m2MatchSequence(m1, m2, direction)に設定する。
    4. m2listOfMatchersへappendする。
  5. singlesを、single characterからなるcsのすべてのCharSetElementを含むCharSetとする。
  6. CharacterSetMatcher(regexpRecord, singles, false, direction)をlistOfMatchersへappendする。
  7. csがcharactersのempty sequenceを含むなら、EmptyMatcher()をlistOfMatchersへappendする。
  8. m2listOfMatchers内のlast Matcherとする。
  9. listOfMatchersの各Matcher m1について、そのsecond-to-last elementからbackwardsにiteratingして、以下を行う
    1. m2MatchTwoAlternatives(m1, m2)に設定する。
  10. m2を返す。
AtomEscape :: k GroupName
  1. matchingGroupSpecifiersGroupSpecifiersThatMatch(GroupName)とする。
  2. parenIndicesを新しい空のListとする。
  3. matchingGroupSpecifiersの各GroupSpecifier groupSpecifierについて、以下を行う
    1. parenIndexCountLeftCapturingParensBefore(groupSpecifier)とする。
    2. parenIndexparenIndicesへappendする。
  4. BackreferenceMatcher(regexpRecord, parenIndices, direction)を返す。

22.2.2.7.1 CharacterSetMatcher ( regexpRecord, charSet, invert, direction )

The abstract operation CharacterSetMatcher takes arguments regexpRecord (a RegExp Record), charSet (a CharSet), invert (a Boolean), and direction (forward or backward) and returns a Matcher. It performs the following steps when called:

  1. regexpRecord.[[UnicodeSets]]trueなら、
    1. Assert: invertfalseである。
    2. Assert: charSetのすべてのCharSetElementはsingle characterからなる。
  2. regexpRecordcharSetinvert、およびdirectionをcaptureし、calledされたときに次のstepsをperformする、parameters (x, c)を持つnew Matcherを返す:
    1. Assert: xMatchStateである。
    2. Assert: cMatcherContinuationである。
    3. inputx.[[Input]]とする。
    4. endIndexx.[[EndIndex]]とする。
    5. directionforwardなら、fendIndex + 1とする。
    6. そうでなければ、fendIndex - 1とする。
    7. inputLengthinput内のelementsの数とする。
    8. f < 0またはf > inputLengthなら、failureを返す。
    9. indexmin(endIndex, f)とする。
    10. charをcharacter input[index]とする。
    11. ccCanonicalize(regexpRecord, char)とする。
    12. Canonicalize(regexpRecord, a)がccであるような、exactly one character aを含むCharSetElementcharSet内に存在するなら、foundtrueとする;そうでなければ、foundfalseとする。
    13. invertfalseであり、かつfoundfalseなら、failureを返す。
    14. inverttrueであり、かつfoundtrueなら、failureを返す。
    15. capabilityx.[[Captures]]とする。
    16. yMatchState { [[Input]]: input, [[EndIndex]]: f, [[Captures]]: capability }とする。
    17. c(y)を返す。

22.2.2.7.2 BackreferenceMatcher ( regexpRecord, ns, direction )

The abstract operation BackreferenceMatcher takes arguments regexpRecord (a RegExp Record), ns (a List of positive integers), and direction (forward or backward) and returns a Matcher. It performs the following steps when called:

  1. regexpRecordns、およびdirectionをcaptureし、calledされたときに次のstepsをperformする、parameters (x, c)を持つnew Matcherを返す:
    1. Assert: xMatchStateである。
    2. Assert: cMatcherContinuationである。
    3. inputx.[[Input]]とする。
    4. capabilityx.[[Captures]]とする。
    5. rundefinedとする。
    6. nsの各integer nについて、以下を行う
      1. capability[n]がundefinedでないなら、
        1. Assert: rundefinedである。
        2. rcapability[n]に設定する。
    7. rundefinedなら、c(x)を返す。
    8. endIndexx.[[EndIndex]]とする。
    9. rsr.[[StartIndex]]とする。
    10. rer.[[EndIndex]]とする。
    11. lengthre - rsとする。
    12. directionforwardなら、fendIndex + lengthとする。
    13. そうでなければ、fendIndex - lengthとする。
    14. inputLengthinput内のelementsの数とする。
    15. f < 0またはf > inputLengthなら、failureを返す。
    16. gmin(endIndex, f)とする。
    17. 0(inclusive)からlength(exclusive)までのinterval内に、Canonicalize(regexpRecord, input[rs + i])がCanonicalize(regexpRecord, input[g + i])でないようなinteger iが存在するなら、failureを返す。
    18. yMatchState { [[Input]]: input, [[EndIndex]]: f, [[Captures]]: capability }とする。
    19. c(y)を返す。

22.2.2.7.3 Canonicalize ( regexpRecord, char )

The abstract operation Canonicalize takes arguments regexpRecord (a RegExp Record) and char (a character) and returns a character. It performs the following steps when called:

  1. HasEitherUnicodeFlag(regexpRecord)がtrueであり、かつregexpRecord.[[IgnoreCase]]trueなら、
    1. Unicode Character Databaseのfile CaseFolding.txtcharに対するsimpleまたはcommon case folding mappingを提供するなら、そのmappingをcharにapplyしたresultを返す。
    2. charを返す。
  2. regexpRecord.[[IgnoreCase]]falseなら、charを返す。
  3. Assert: charはUTF-16 code unitである。
  4. codePointをnumeric valueがcharのnumeric valueであるcode pointとする。
  5. uを、Unicode Default Case Conversion algorithmに従ったtoUppercase(« codePoint »)とする。
  6. uStringCodePointsToString(u)とする。
  7. uStringのlength ≠ 1なら、charを返す。
  8. codeUnituStringのsingle code unit elementとする。
  9. charのnumeric value ≥ 128であり、かつcodeUnitのnumeric value < 128なら、charを返す。
  10. codeUnitを返す。
Note

HasEitherUnicodeFlag(regexpRecord)がtrueであるcase-insignificant matchesでは、すべてのcharactersは、comparedされる直前にUnicode Standardによってprovidedされるsimple mappingを使用してimplicitly case-foldedされます。simple mappingは常にsingle code pointへmapするため、例えばß(U+00DF LATIN SMALL LETTER SHARP S)をssSSへmapしません。ただし、Basic Latin blockの外側にあるcode pointsをその内側のcode pointsへmapすることはあります—例えば、ſ(U+017F LATIN SMALL LETTER LONG S)はs(U+0073 LATIN SMALL LETTER S)へcase-foldし、(U+212A KELVIN SIGN)はk(U+006B LATIN SMALL LETTER K)へcase-foldします。それらのcode pointsを含むStringsは/[a-z]/uiのようなregular expressionsによってmatchedされます。

HasEitherUnicodeFlag(regexpRecord)がfalseであるcase-insignificant matchesでは、mappingはtoCasefoldではなくUnicode Default Case Conversion algorithm toUppercaseに基づくため、いくつかのsubtle differencesが生じます。例えば、(U+2126 OHM SIGN)はtoUppercaseではitselfへmappedされますが、toCasefoldではΩ(U+03A9 GREEK CAPITAL LETTER OMEGA)とともにω(U+03C9 GREEK SMALL LETTER OMEGA)へmappedされるため、"\u2126"/[ω]/uiおよび/[\u03A9]/uiによってmatchedされますが、/[ω]/iまたは/[\u03A9]/iによってはmatchedされません。また、Basic Latin blockの外側のcode pointはその内側のcode pointへmappedされないため、"\u017F ſ""\u212A K"のようなstringsは/[a-z]/iによってmatchedされません。

22.2.2.7.4 UpdateModifiers ( regexpRecord, add, remove )

The abstract operation UpdateModifiers takes arguments regexpRecord (a RegExp Record), add (a String), and remove (a String) and returns a RegExp Record. It performs the following steps when called:

  1. Assert: addおよびremoveはcommon elementsを持たない。
  2. ignoreCaseregexpRecord.[[IgnoreCase]]とする。
  3. multilineregexpRecord.[[Multiline]]とする。
  4. dotAllregexpRecord.[[DotAll]]とする。
  5. unicoderegexpRecord.[[Unicode]]とする。
  6. unicodeSetsregexpRecord.[[UnicodeSets]]とする。
  7. capturingGroupsCountregexpRecord.[[CapturingGroupsCount]]とする。
  8. remove"i"を含むなら、ignoreCasefalseに設定する。
  9. そうでなく、add"i"を含むなら、ignoreCasetrueに設定する。
  10. remove"m"を含むなら、multilinefalseに設定する。
  11. そうでなく、add"m"を含むなら、multilinetrueに設定する。
  12. remove"s"を含むなら、dotAllfalseに設定する。
  13. そうでなく、add"s"を含むなら、dotAlltrueに設定する。
  14. RegExp Record { [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline, [[DotAll]]: dotAll, [[Unicode]]: unicode, [[UnicodeSets]]: unicodeSets, [[CapturingGroupsCount]]: capturingGroupsCount }を返す。

22.2.2.8 Runtime Semantics: CompileCharacterClass

The syntax-directed operation CompileCharacterClass takes argument regexpRecord (a RegExp Record) and returns a Record with fields [[CharSet]] (a CharSet) and [[Invert]] (a Boolean). It is defined piecewise over the following productions:

CharacterClass :: [ ClassContents ]
  1. charSetをargument regexpRecordを伴うClassContentsCompileToCharSetとする。
  2. Record { [[CharSet]]: charSet, [[Invert]]: false }を返す。
CharacterClass :: [^ ClassContents ]
  1. charSetをargument regexpRecordを伴うClassContentsCompileToCharSetとする。
  2. regexpRecord.[[UnicodeSets]]trueなら、
    1. Record { [[CharSet]]: CharacterComplement(regexpRecord, charSet), [[Invert]]: false }を返す。
  3. Record { [[CharSet]]: charSet, [[Invert]]: true }を返す。

22.2.2.9 Runtime Semantics: CompileToCharSet

The syntax-directed operation CompileToCharSet takes argument regexpRecord (a RegExp Record) and returns a CharSet.

Note 1

このsectionはB.1.2.8でamendedされます。

It is defined piecewise over the following productions:

ClassContents :: [empty]
  1. empty CharSetを返す。
NonemptyClassRanges :: ClassAtom NonemptyClassRangesNoDash
  1. charSetをargument regexpRecordを伴うClassAtomCompileToCharSetとする。
  2. otherSetをargument regexpRecordを伴うNonemptyClassRangesNoDashCompileToCharSetとする。
  3. CharSets charSetおよびotherSetのunionを返す。
NonemptyClassRanges :: ClassAtom - ClassAtom ClassContents
  1. charSetをargument regexpRecordを伴うfirst ClassAtomCompileToCharSetとする。
  2. otherSetをargument regexpRecordを伴うsecond ClassAtomCompileToCharSetとする。
  3. remainingSetをargument regexpRecordを伴うClassContentsCompileToCharSetとする。
  4. rangeSetCharacterRange(charSet, otherSet)とする。
  5. rangeSetおよびremainingSetのunionを返す。
NonemptyClassRangesNoDash :: ClassAtomNoDash NonemptyClassRangesNoDash
  1. charSetをargument regexpRecordを伴うClassAtomNoDashCompileToCharSetとする。
  2. otherSetをargument regexpRecordを伴うNonemptyClassRangesNoDashCompileToCharSetとする。
  3. CharSets charSetおよびotherSetのunionを返す。
NonemptyClassRangesNoDash :: ClassAtomNoDash - ClassAtom ClassContents
  1. charSetをargument regexpRecordを伴うClassAtomNoDashCompileToCharSetとする。
  2. otherSetをargument regexpRecordを伴うClassAtomCompileToCharSetとする。
  3. remainingSetをargument regexpRecordを伴うClassContentsCompileToCharSetとする。
  4. rangeSetCharacterRange(charSet, otherSet)とする。
  5. rangeSetおよびremainingSetのunionを返す。
Note 2

ClassContentsは、single ClassAtom、および/またはdashesでseparatedされたtwo ClassAtomのrangesへexpandできます。後者の場合、ClassContentsはfirst ClassAtomとsecond ClassAtomの間にあるすべてのcharactersをinclusiveに含みます;いずれかのClassAtomがsingle characterをrepresentしない場合(例えば、一方が\wである場合)、またはfirst ClassAtomのcharacter valueがsecond ClassAtomのcharacter valueよりstrictly greaterである場合、errorが発生します。

Note 3

patternがcaseをignoreする場合でも、rangeのtwo endsのcaseは、どのcharactersがrangeに属するかをdetermineする上でsignificantです。したがって、例えば、pattern /[E-F]/iはletters EFe、およびfのみにmatchします。一方、pattern /[E-f]/iはUnicode Basic Latin block内のすべてのuppercaseおよびlowercase lettersに加えて、symbols [, \, ], ^, _, and `にもmatchします。

Note 4

- characterはliterallyに扱われることも、rangeをdenoteすることもできます。これは、ClassContentsのfirstまたはlast characterである場合、range specificationのbeginningまたはend limitである場合、またはrange specificationの直後にfollowする場合、literallyに扱われます。

ClassAtom :: -
  1. single character - U+002D (HYPHEN-MINUS)を含むCharSetを返す。
ClassAtomNoDash :: SourceCharacter but not one of \ or ] or -
  1. SourceCharacterにmatchedするcharacterを含むCharSetを返す。
ClassEscape :: b - CharacterEscape
  1. charValueをこのClassEscapeCharacterValueとする。
  2. charをcharacter valueがcharValueであるcharacterとする。
  3. single character charを含むCharSetを返す。
Note 5

ClassAtomは、\b\B、およびbackreferencesを除き、regular expressionのrestでallowedされる任意のescape sequencesを使用できます。CharacterClassの内側では、\bはbackspace characterを意味し、\Bおよびbackreferencesはerrorsをraiseします。ClassAtomの内側でbackreferenceを使用するとerrorが発生します。

CharacterClassEscape :: d
  1. characters 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9を含むten-element CharSetを返す。
CharacterClassEscape :: D
  1. charSet CharacterClassEscape :: d によってreturnedされるCharSetとする。
  2. CharacterComplement(regexpRecord, charSet)を返す。
CharacterClassEscape :: s
  1. WhiteSpaceまたはLineTerminator productionsのright-hand side上のcode pointに対応するすべてのcharactersを含むCharSetを返す。
CharacterClassEscape :: S
  1. charSet CharacterClassEscape :: s によってreturnedされるCharSetとする。
  2. CharacterComplement(regexpRecord, charSet)を返す。
CharacterClassEscape :: w
  1. MaybeSimpleCaseFolding(regexpRecord, WordCharacters(regexpRecord))を返す。
CharacterClassEscape :: W
  1. charSet CharacterClassEscape :: w によってreturnedされるCharSetとする。
  2. CharacterComplement(regexpRecord, charSet)を返す。
CharacterClassEscape :: p{ UnicodePropertyValueExpression }
  1. argument regexpRecordを伴うUnicodePropertyValueExpressionCompileToCharSetを返す。
CharacterClassEscape :: P{ UnicodePropertyValueExpression }
  1. charSetをargument regexpRecordを伴うUnicodePropertyValueExpressionCompileToCharSetとする。
  2. Assert: charSetはsingle code pointsのみを含む。
  3. CharacterComplement(regexpRecord, charSet)を返す。
UnicodePropertyValueExpression :: UnicodePropertyName = UnicodePropertyValue
  1. psUnicodePropertyNameにmatchedするsource textとする。
  2. pUnicodeMatchProperty(regexpRecord, ps)とする。
  3. Assert: pTable 65の“Property name and aliases” columnにlistedされているUnicode property nameまたはproperty aliasである。
  4. vsUnicodePropertyValueにmatchedするsource textとする。
  5. vUnicodeMatchPropertyValue(p, vs)とする。
  6. charSetを、character database definitionがproperty p with value vを含むすべてのUnicode code pointsを含むCharSetとする。
  7. MaybeSimpleCaseFolding(regexpRecord, charSet)を返す。
UnicodePropertyValueExpression :: LoneUnicodePropertyNameOrValue
  1. sLoneUnicodePropertyNameOrValueにmatchedするsource textとする。
  2. UnicodeMatchPropertyValue(General_Category, s)が、PropertyValueAliases.txtにlistedされているGeneral_Category (gc) propertyに対するUnicode property valueまたはproperty value aliasであるなら、
    1. “General_Category” property with value sをcharacter database definitionが含むすべてのUnicode code pointsを含むCharSetを返す。
  3. pUnicodeMatchProperty(regexpRecord, s)とする。
  4. Assert: pTable 66の“Property name and aliases” columnにlistedされているbinary Unicode propertyまたはbinary property alias、またはTable 67の“Property name” columnにlistedされているbinary Unicode property of stringsである。
  5. charSetを、character database definitionがproperty p with value “True”を含むすべてのCharSetElementsを含むCharSetとする。
  6. MaybeSimpleCaseFolding(regexpRecord, charSet)を返す。
ClassUnion :: ClassSetRange ClassUnionopt
  1. charSetをargument regexpRecordを伴うClassSetRangeCompileToCharSetとする。
  2. ClassUnionがpresentなら、
    1. otherSetをargument regexpRecordを伴うClassUnionCompileToCharSetとする。
    2. CharSets charSetおよびotherSetのunionを返す。
  3. charSetを返す。
ClassUnion :: ClassSetOperand ClassUnionopt
  1. charSetをargument regexpRecordを伴うClassSetOperandCompileToCharSetとする。
  2. ClassUnionがpresentなら、
    1. otherSetをargument regexpRecordを伴うClassUnionCompileToCharSetとする。
    2. CharSets charSetおよびotherSetのunionを返す。
  3. charSetを返す。
ClassIntersection :: ClassSetOperand && ClassSetOperand
  1. charSetをargument regexpRecordを伴うfirst ClassSetOperandCompileToCharSetとする。
  2. otherSetをargument regexpRecordを伴うsecond ClassSetOperandCompileToCharSetとする。
  3. CharSets charSetおよびotherSetのintersectionを返す。
ClassIntersection :: ClassIntersection && ClassSetOperand
  1. charSetをargument regexpRecordを伴うClassIntersectionCompileToCharSetとする。
  2. otherSetをargument regexpRecordを伴うClassSetOperandCompileToCharSetとする。
  3. CharSets charSetおよびotherSetのintersectionを返す。
ClassSubtraction :: ClassSetOperand -- ClassSetOperand
  1. charSetをargument regexpRecordを伴うfirst ClassSetOperandCompileToCharSetとする。
  2. otherSetをargument regexpRecordを伴うsecond ClassSetOperandCompileToCharSetとする。
  3. otherSetのCharSetElementsでもあるものを除いた、charSetのCharSetElementsを含むCharSetを返す。
ClassSubtraction :: ClassSubtraction -- ClassSetOperand
  1. charSetをargument regexpRecordを伴うClassSubtractionCompileToCharSetとする。
  2. otherSetをargument regexpRecordを伴うClassSetOperandCompileToCharSetとする。
  3. otherSetのCharSetElementsでもあるものを除いた、charSetのCharSetElementsを含むCharSetを返す。
ClassSetRange :: ClassSetCharacter - ClassSetCharacter
  1. charSetをargument regexpRecordを伴うfirst ClassSetCharacterCompileToCharSetとする。
  2. otherSetをargument regexpRecordを伴うsecond ClassSetCharacterCompileToCharSetとする。
  3. MaybeSimpleCaseFolding(regexpRecord, CharacterRange(charSet, otherSet))を返す。
Note 6

resultはしばしばtwo or more rangesから構成されます。UnicodeSetsがtrueでありIgnoreCaseがtrueである場合、MaybeSimpleCaseFolding(regexpRecord, [Ā-č])はそのrangeのodd-numbered code pointsのみを含みます。

ClassSetOperand :: ClassSetCharacter
  1. charSetをargument regexpRecordを伴うClassSetCharacterCompileToCharSetとする。
  2. MaybeSimpleCaseFolding(regexpRecord, charSet)を返す。
ClassSetOperand :: ClassStringDisjunction
  1. charSetをargument regexpRecordを伴うClassStringDisjunctionCompileToCharSetとする。
  2. MaybeSimpleCaseFolding(regexpRecord, charSet)を返す。
ClassSetOperand :: NestedClass
  1. argument regexpRecordを伴うNestedClassCompileToCharSetを返す。
NestedClass :: [ ClassContents ]
  1. argument regexpRecordを伴うClassContentsCompileToCharSetを返す。
NestedClass :: [^ ClassContents ]
  1. charSetをargument regexpRecordを伴うClassContentsCompileToCharSetとする。
  2. CharacterComplement(regexpRecord, charSet)を返す。
NestedClass :: \ CharacterClassEscape
  1. argument regexpRecordを伴うCharacterClassEscapeCompileToCharSetを返す。
ClassStringDisjunction :: \q{ ClassStringDisjunctionContents }
  1. argument regexpRecordを伴うClassStringDisjunctionContentsCompileToCharSetを返す。
ClassStringDisjunctionContents :: ClassString
  1. sをargument regexpRecordを伴うClassStringCompileClassSetStringとする。
  2. one string sを含むCharSetを返す。
ClassStringDisjunctionContents :: ClassString | ClassStringDisjunctionContents
  1. sをargument regexpRecordを伴うClassStringCompileClassSetStringとする。
  2. charSetをone string sを含むCharSetとする。
  3. otherSetをargument regexpRecordを伴うClassStringDisjunctionContentsCompileToCharSetとする。
  4. CharSets charSetおよびotherSetのunionを返す。
ClassSetCharacter :: SourceCharacter but not ClassSetSyntaxCharacter \ CharacterEscape \ ClassSetReservedPunctuator
  1. charValueをこのClassSetCharacterCharacterValueとする。
  2. charをcharacter valueがcharValueであるcharacterとする。
  3. single character charを含むCharSetを返す。
ClassSetCharacter :: \b
  1. single character U+0008 (BACKSPACE)を含むCharSetを返す。

22.2.2.9.1 CharacterRange ( charSet, otherSet )

The abstract operation CharacterRange takes arguments charSet (a CharSet) and otherSet (a CharSet) and returns a CharSet. It performs the following steps when called:

  1. Assert: charSetおよびotherSetはそれぞれexactly one characterを含む。
  2. aCharSet charSet内のone characterとする。
  3. bCharSet otherSet内のone characterとする。
  4. iをcharacter aのcharacter valueとする。
  5. jをcharacter bのcharacter valueとする。
  6. Assert: ijである。
  7. iからjまでのinclusive interval内のcharacter valueを持つすべてのcharactersを含むCharSetを返す。

22.2.2.9.2 HasEitherUnicodeFlag ( regexpRecord )

The abstract operation HasEitherUnicodeFlag takes argument regexpRecord (a RegExp Record) and returns a Boolean. It performs the following steps when called:

  1. regexpRecord.[[Unicode]]trueまたはregexpRecord.[[UnicodeSets]]trueなら、trueを返す。
  2. falseを返す。

22.2.2.9.3 WordCharacters ( regexpRecord )

The abstract operation WordCharacters takes argument regexpRecord (a RegExp Record) and returns a CharSet. \b\B\w、および\Wのpurposesにおいて“word characters”とconsideredされるcharactersを含むCharSetを返します。 It performs the following steps when called:

  1. basicWordCharsをASCII word characters内のすべてのcharacterを含むCharSetとする。
  2. extraWordCharsを、basicWordChars内にないがCanonicalize(regexpRecord, c)がbasicWordChars内にあるようなすべてのcharacters cを含むCharSetとする。
  3. Assert: HasEitherUnicodeFlag(regexpRecord)がtrueかつregexpRecord.[[IgnoreCase]]trueでない限り、extraWordCharsはemptyである。
  4. basicWordCharsおよびextraWordCharsのunionを返す。

22.2.2.9.4 AllCharacters ( regexpRecord )

The abstract operation AllCharacters takes argument regexpRecord (a RegExp Record) and returns a CharSet. regular expression flagsに従った“all characters”のsetを返します。 It performs the following steps when called:

  1. regexpRecord.[[UnicodeSets]]trueであり、かつregexpRecord.[[IgnoreCase]]trueなら、
    1. Simple Case Folding mappingを持たない(すなわち、scf(c)=cである)すべてのUnicode code points cを含むCharSetを返す。
  2. HasEitherUnicodeFlag(regexpRecord)がtrueなら、
    1. すべてのcode point valuesを含むCharSetを返す。
  3. すべてのcode unit valuesを含むCharSetを返す。

22.2.2.9.5 MaybeSimpleCaseFolding ( regexpRecord, charSet )

The abstract operation MaybeSimpleCaseFolding takes arguments regexpRecord (a RegExp Record) and charSet (a CharSet) and returns a CharSet. regexpRecord.[[UnicodeSets]]falseまたはregexpRecord.[[IgnoreCase]]falseである場合、charSetを返します。そうでなければ、Unicode Character Databaseのfile CaseFolding.txt内のSimple Case Foldingscf(codePoint))definitions(それぞれsingle code pointをanother single code pointへmapする)を使用して、charSetの各CharSetElementをcharacter-by-characterにcanonical formへmapし、resulting CharSetを返します。 It performs the following steps when called:

  1. regexpRecord.[[UnicodeSets]]falseまたはregexpRecord.[[IgnoreCase]]falseなら、charSetを返す。
  2. otherSetをnew empty CharSetとする。
  3. charSetの各CharSetElement sについて、以下を行う
    1. tをcharactersのempty sequenceとする。
    2. s内の各single code point codePointについて、以下を行う
      1. scf(codePoint)をtへappendする。
    3. totherSetへaddする。
  4. otherSetを返す。

22.2.2.9.6 CharacterComplement ( regexpRecord, complement )

The abstract operation CharacterComplement takes arguments regexpRecord (a RegExp Record) and complement (a CharSet) and returns a CharSet. It performs the following steps when called:

  1. charSetAllCharacters(regexpRecord)とする。
  2. complementのCharSetElementsでもあるものを除いた、charSetのCharSetElementsを含むCharSetを返す。

22.2.2.9.7 UnicodeMatchProperty ( regexpRecord, p )

The abstract operation UnicodeMatchProperty takes arguments regexpRecord (a RegExp Record) and p (ECMAScript source text) and returns a Unicode property name. It performs the following steps when called:

  1. regexpRecord.[[UnicodeSets]]trueであり、かつpTable 67の“Property name” columnにlistedされているUnicode property nameであるなら、
    1. Unicode code points pListを返す。
  2. Assert: pTable 65またはTable 66の“Property name and aliases” columnにlistedされているUnicode property nameまたはproperty aliasである。
  3. cを、corresponding rowの“Canonical property name” columnでgivenされたpのcanonical property nameとする。
  4. Unicode code points cListを返す。

Implementationsは、Table 65Table 66、およびTable 67にlistedされているUnicode property namesおよびaliasesをsupportしなければなりません。interoperabilityをensureするため、implementationsは他のproperty namesまたはaliasesをsupportしてはなりません。

Note 1

例えば、Script_Extensionsproperty name)およびscx(property alias)はvalidですが、script_extensionsScxはvalidではありません。

Note 2

listed propertiesは、UTS18 RL1.2がrequireするもののsupersetを形成します。

Note 3

これらのtables内のentriesのspellings(casingを含む)は、Unicode Character Databaseのfile PropertyAliases.txtで使用されるspellingsとmatchします。そのfile内のprecise spellingsはstableであることがguaranteedされています

Table 65: Non-binary Unicode property aliases and their canonical property names
Property name and aliases Canonical property name
General_Category General_Category
gc
Script Script
sc
Script_Extensions Script_Extensions
scx
Table 66: Binary Unicode property aliases and their canonical property names
Property name and aliases Canonical property name
ASCII ASCII
ASCII_Hex_Digit ASCII_Hex_Digit
AHex
Alphabetic Alphabetic
Alpha
Any Any
Assigned Assigned
Bidi_Control Bidi_Control
Bidi_C
Bidi_Mirrored Bidi_Mirrored
Bidi_M
Case_Ignorable Case_Ignorable
CI
Cased Cased
Changes_When_Casefolded Changes_When_Casefolded
CWCF
Changes_When_Casemapped Changes_When_Casemapped
CWCM
Changes_When_Lowercased Changes_When_Lowercased
CWL
Changes_When_NFKC_Casefolded Changes_When_NFKC_Casefolded
CWKCF
Changes_When_Titlecased Changes_When_Titlecased
CWT
Changes_When_Uppercased Changes_When_Uppercased
CWU
Dash Dash
Default_Ignorable_Code_Point Default_Ignorable_Code_Point
DI
Deprecated Deprecated
Dep
Diacritic Diacritic
Dia
Emoji Emoji
Emoji_Component Emoji_Component
EComp
Emoji_Modifier Emoji_Modifier
EMod
Emoji_Modifier_Base Emoji_Modifier_Base
EBase
Emoji_Presentation Emoji_Presentation
EPres
Extended_Pictographic Extended_Pictographic
ExtPict
Extender Extender
Ext
Grapheme_Base Grapheme_Base
Gr_Base
Grapheme_Extend Grapheme_Extend
Gr_Ext
Hex_Digit Hex_Digit
Hex
IDS_Binary_Operator IDS_Binary_Operator
IDSB
IDS_Trinary_Operator IDS_Trinary_Operator
IDST
ID_Continue ID_Continue
IDC
ID_Start ID_Start
IDS
Ideographic Ideographic
Ideo
Join_Control Join_Control
Join_C
Logical_Order_Exception Logical_Order_Exception
LOE
Lowercase Lowercase
Lower
Math Math
Noncharacter_Code_Point Noncharacter_Code_Point
NChar
Pattern_Syntax Pattern_Syntax
Pat_Syn
Pattern_White_Space Pattern_White_Space
Pat_WS
Quotation_Mark Quotation_Mark
QMark
Radical Radical
Regional_Indicator Regional_Indicator
RI
Sentence_Terminal Sentence_Terminal
STerm
Soft_Dotted Soft_Dotted
SD
Terminal_Punctuation Terminal_Punctuation
Term
Unified_Ideograph Unified_Ideograph
UIdeo
Uppercase Uppercase
Upper
Variation_Selector Variation_Selector
VS
White_Space White_Space
space
XID_Continue XID_Continue
XIDC
XID_Start XID_Start
XIDS
Table 67: Binary Unicode properties of strings
Property name
Basic_Emoji
Emoji_Keycap_Sequence
RGI_Emoji_Modifier_Sequence
RGI_Emoji_Flag_Sequence
RGI_Emoji_Tag_Sequence
RGI_Emoji_ZWJ_Sequence
RGI_Emoji

22.2.2.9.8 UnicodeMatchPropertyValue ( p, v )

The abstract operation UnicodeMatchPropertyValue takes arguments p (ECMAScript source text) and v (ECMAScript source text) and returns a Unicode property value. It performs the following steps when called:

  1. Assert: pTable 65の“Canonical property name” columnにlistedされているcanonicalかつunaliasedなUnicode property nameである。
  2. Assert: vはUnicode property pに対するproperty valueまたはproperty value aliasであり、PropertyValueAliases.txtにlistedされている。
  3. valueを、corresponding rowの“Canonical property value” columnでgivenされたvのcanonical property valueとする。
  4. Unicode code points valueListを返す。

Implementationsは、Table 65にlistedされているpropertiesについて、PropertyValueAliases.txtにlistedされているUnicode property valuesおよびproperty value aliasesをsupportしなければなりません。interoperabilityをensureするため、implementationsは他のproperty valuesまたはproperty value aliasesをsupportしてはなりません。

Note 1

例えば、XpeoおよびOld_PersianはvalidなScript_Extensions valuesですが、xpeoおよびOld Persianはvalidではありません。

Note 2

このalgorithmはUAX44にlistedされているsymbolic valuesのmatching rulesとは異なります:case、white space、U+002D (HYPHEN-MINUS)、およびU+005F (LOW LINE)はignoredされず、Is prefixはsupportされません。

22.2.2.10 Runtime Semantics: CompileClassSetString

The syntax-directed operation CompileClassSetString takes argument regexpRecord (a RegExp Record) and returns a sequence of characters. It is defined piecewise over the following productions:

ClassString :: [empty]
  1. charactersのempty sequenceを返す。
ClassString :: NonEmptyClassString
  1. argument regexpRecordを伴うNonEmptyClassStringCompileClassSetStringを返す。
NonEmptyClassString :: ClassSetCharacter NonEmptyClassStringopt
  1. csをargument regexpRecordを伴うClassSetCharacterCompileToCharSetとする。
  2. s1を、csのsingle CharSetElementであるcharactersのsequenceとする。
  3. NonEmptyClassStringがpresentなら、
    1. s2をargument regexpRecordを伴うNonEmptyClassStringCompileClassSetStringとする。
    2. s1s2のconcatenationを返す。
  4. s1を返す。

22.2.3 Abstract Operations for RegExp Creation

22.2.3.1 RegExpCreate ( pattern, flags )

The abstract operation RegExpCreate takes arguments pattern (an ECMAScript language value) and flags (a String or undefined) and returns either a normal completion containing an Object or a throw completion. It performs the following steps when called:

  1. objを ! RegExpAlloc(%RegExp%) とする。
  2. RegExpInitialize(obj, pattern, flags)を返す。

22.2.3.2 RegExpAlloc ( newTarget )

The abstract operation RegExpAlloc takes argument newTarget (a constructor) and returns either a normal completion containing an Object or a throw completion. It performs the following steps when called:

  1. objを ? OrdinaryCreateFromConstructor(newTarget, "%RegExp.prototype%", « [[OriginalSource]], [[OriginalFlags]], [[RegExpRecord]], [[RegExpMatcher]] ») とする。
  2. DefinePropertyOrThrow(obj, "lastIndex", PropertyDescriptor { [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })を実行する。
  3. objを返す。

22.2.3.3 RegExpInitialize ( obj, pattern, flags )

The abstract operation RegExpInitialize takes arguments obj (an Object), pattern (an ECMAScript language value), and flags (an ECMAScript language value) and returns either a normal completion containing an Object or a throw completion. It performs the following steps when called:

  1. patternundefinedなら、patternをempty Stringに設定する。
  2. そうでなければ、patternを ? ToString(pattern) に設定する。
  3. flagsundefinedなら、flagsをempty Stringに設定する。
  4. そうでなければ、flagsを ? ToString(flags) に設定する。
  5. flags"d""g""i""m""s""u""v"、または"y"以外のcode unitを含むなら、SyntaxError例外をthrowする。
  6. flagsが同じcode unitを複数回含むなら、SyntaxError例外をthrowする。
  7. flags"i"を含むなら、itrueとする;そうでなければ、ifalseとする。
  8. flags"m"を含むなら、mtrueとする;そうでなければ、mfalseとする。
  9. flags"s"を含むなら、strueとする;そうでなければ、sfalseとする。
  10. flags"u"を含むなら、utrueとする;そうでなければ、ufalseとする。
  11. flags"v"を含むなら、vtrueとする;そうでなければ、vfalseとする。
  12. utrueまたはvtrueなら、
    1. patternTextStringToCodePoints(pattern)とする。
  13. そうでなければ、
    1. patternTextを、patternの各16-bit elementをUnicode BMP code pointとしてinterpretingしたresultとする。UTF-16 decodingはelementsにapplyされない。
  14. parseResultParsePattern(patternText, u, v)とする。
  15. parseResultSyntaxError objectsのnon-empty Listなら、SyntaxError例外をthrowする。
  16. Assert: parseResultPattern Parse Nodeである。
  17. obj.[[OriginalSource]]patternに設定する。
  18. obj.[[OriginalFlags]]flagsに設定する。
  19. capturingGroupsCountCountLeftCapturingParensWithin(parseResult)とする。
  20. regexpRecordRegExp Record { [[IgnoreCase]]: i, [[Multiline]]: m, [[DotAll]]: s, [[Unicode]]: u, [[UnicodeSets]]: v, [[CapturingGroupsCount]]: capturingGroupsCount }とする。
  21. obj.[[RegExpRecord]]regexpRecordに設定する。
  22. obj.[[RegExpMatcher]]を、argument regexpRecordを伴うparseResultCompilePatternに設定する。
  23. Set(obj, "lastIndex", +0𝔽, true)を実行する。
  24. objを返す。

22.2.3.4 Static Semantics: ParsePattern ( patternText, u, v )

The abstract operation ParsePattern takes arguments patternText (a sequence of Unicode code points), u (a Boolean), and v (a Boolean) and returns a Parse Node or a non-empty List of SyntaxError objects.

Note

このsectionはB.1.2.9でamendedされます。

It performs the following steps when called:

  1. vtrueであり、かつutrueなら、
    1. parseResultを、one or more SyntaxError objectsを含むListとする。
  2. そうでなく、vtrueなら、
    1. parseResultParseText(patternText, Pattern[+UnicodeMode, +UnicodeSetsMode, +NamedCaptureGroups])とする。
  3. そうでなく、utrueなら、
    1. parseResultParseText(patternText, Pattern[+UnicodeMode, ~UnicodeSetsMode, +NamedCaptureGroups])とする。
  4. そうでなければ、
    1. parseResultParseText(patternText, Pattern[~UnicodeMode, ~UnicodeSetsMode, +NamedCaptureGroups])とする。
  5. parseResultを返す。

22.2.4 The RegExp Constructor

RegExp constructorは:

  • %RegExp%です。
  • global object"RegExp" propertyのinitial valueです。
  • constructorとして呼び出されたとき、新しいRegExp objectを作成およびinitializeします。
  • constructorとしてではなくfunctionとして呼び出されたとき、新しいRegExp object、またはonly argumentがRegExp objectである場合はargument自体のいずれかを返します。
  • class definitionのextends clauseのvalueとして使用できます。指定されたRegExp behaviourをinheritしようとするsubclass constructorsは、必要なinternal slotsを持つsubclass instancesを作成およびinitializeするために、RegExp constructorへのsuper callを含まなければなりません。

22.2.4.1 RegExp ( patternOrRegexp, flags )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. patternIsRegExpを ? IsRegExp(patternOrRegexp) とする。
  2. NewTargetがundefinedなら、
    1. newTargetactive function objectとする。
    2. patternIsRegExptrueであり、かつflagsundefinedなら、
      1. patternCtorを ? Get(patternOrRegexp, "constructor") とする。
      2. SameValue(newTarget, patternCtor)がtrueなら、patternOrRegexpを返す。
  3. そうでなければ、
    1. newTargetをNewTargetとする。
  4. patternOrRegexpがObjectであり、かつpatternOrRegexp[[RegExpMatcher]] internal slotを持つなら、
    1. patternSourcepatternOrRegexp.[[OriginalSource]]とする。
    2. flagsundefinedなら、flagspatternOrRegexp.[[OriginalFlags]]に設定する。
  5. そうでなく、patternIsRegExptrueなら、
    1. patternSourceを ? Get(patternOrRegexp, "source") とする。
    2. flagsundefinedなら、
      1. flagsを ? Get(patternOrRegexp, "flags") に設定する。
  6. そうでなければ、
    1. patternSourcepatternOrRegexpとする。
  7. objを ? RegExpAlloc(newTarget) とする。
  8. RegExpInitialize(obj, patternSource, flags)を返す。
Note

patternがStringLiteralを使用してsuppliedされる場合、Stringがこのfunctionによってprocessedされる前にusual escape sequence substitutionsがperformedされます。patternがこのfunctionによってrecognizedされるためにescape sequenceを含まなければならない場合、StringLiteralのcontentsがformedされるときにU+005C (REVERSE SOLIDUS) code pointsがremovedされることをpreventするため、任意のU+005C (REVERSE SOLIDUS) code pointsはStringLiteral内でescapedされなければなりません。

22.2.5 Properties of the RegExp Constructor

RegExp constructorは:

  • valueが%Function.prototype%である[[Prototype]] internal slotを持ちます。
  • 次のpropertiesを持ちます:

22.2.5.1 RegExp.escape ( string )

このfunctionは、regular expression Pattern内でpotentially specialであるcharactersがequivalent escape sequencesで置き換えられたstringのcopyを返します。

これは呼び出されたとき、次のstepsを実行します:

  1. stringがStringでないなら、TypeError例外をthrowする。
  2. escapedをempty Stringとする。
  3. codePointListStringToCodePoints(string)とする。
  4. codePointListの各code point codePointについて、以下を行う
    1. escapedがempty Stringであり、かつcodePointDecimalDigitまたはAsciiLetterのいずれかによってmatchedされるなら、
      1. NOTE: leading digitをescapeすると、outputが、\0 character escapeまたは\1のようなDecimalEscapeの後に使用され得るpattern textに対応し、preceding escape sequenceのextensionとしてinterpretedされるのではなく、なおstringにmatchすることをensureする。leading ASCII letterをescapeすることは、\cの後のcontextについて同じことを行う。
      2. numericValuecodePointのnumeric valueとする。
      3. hexNumber::toString(𝔽(numericValue), 16)とする。
      4. Assert: hexのlengthは2である。
      5. escapedをcode unit 0x005C (REVERSE SOLIDUS)、"x"、およびhexstring-concatenationに設定する。
    2. そうでなければ、
      1. escapedescapedEncodeForRegExpEscape(codePoint)のstring-concatenationに設定する。
  5. escapedを返す。
Note

similar namesを持つにもかかわらず、EscapeRegExpPatternRegExp.escapeはsimilar actionsをperformしません。前者はstringとしてrepresentationするためにpatternをescapeし、このfunctionはpatternの内側でrepresentationするためにstringをescapeします。

22.2.5.1.1 EncodeForRegExpEscape ( codePoint )

The abstract operation EncodeForRegExpEscape takes argument codePoint (a code point) and returns a String. これはcodePointにmatchingするためのPatternを表すStringを返します。codePointがwhite spaceまたはASCII punctuatorである場合、returned valueはescape sequenceです。そうでなければ、returned valueはcodePoint自体のString representationです。 It performs the following steps when called:

  1. codePointSyntaxCharacterによってmatchedされる、またはcodePointがU+002F (SOLIDUS)であるなら、
    1. 0x005C (REVERSE SOLIDUS)とUTF16EncodeCodePoint(codePoint)のstring-concatenationを返す。
  2. codePointTable 63の“Code Point” columnにlistedされているcode pointなら、
    1. 0x005C (REVERSE SOLIDUS)と、“Code Point” columnがcodePointを含むrowの“ControlEscape” column内のstringのstring-concatenationを返す。
  3. otherPunctuators",-=<>#&!%:;@~'`"とcode unit 0x0022 (QUOTATION MARK)のstring-concatenationとする。
  4. toEscapeStringToCodePoints(otherPunctuators)とする。
  5. toEscapecodePointを含む、codePointWhiteSpaceまたはLineTerminatorのいずれかによってmatchedされる、またはcodePointleading surrogateまたはtrailing surrogateとsame numeric valueを持つなら、
    1. codePointNumbercodePointのnumeric valueとする。
    2. codePointNumber ≤ 0xFFなら、
      1. hexNumber::toString(𝔽(codePointNumber), 16)とする。
      2. code unit 0x005C (REVERSE SOLIDUS)、"x"、およびStringPad(hex, 2, "0", start)のstring-concatenationを返す。
    3. escapedをempty Stringとする。
    4. codeUnitsUTF16EncodeCodePoint(codePoint)とする。
    5. codeUnitsの各code unit codeUnitについて、以下を行う
      1. escapedescapedUnicodeEscape(codeUnit)のstring-concatenationに設定する。
    6. escapedを返す。
  6. UTF16EncodeCodePoint(codePoint)を返す。

22.2.5.2 RegExp.prototype

RegExp.prototypeのinitial valueはRegExp prototype objectです。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

22.2.5.3 get RegExp [ %Symbol.species% ]

RegExp[%Symbol.species%]は、set accessor functionがundefinedであるaccessor propertyです。そのget accessor functionは呼び出されたとき、次のstepsを実行します:

  1. this valueを返す。

このfunctionの"name" propertyのvalueは"get [Symbol.species]"です。

Note

RegExp prototype methodsは通常、そのthis valueのconstructorを使用してderived objectを作成します。しかし、subclass constructorは、その%Symbol.species% propertyをredefiningすることにより、そのdefault behaviourをover-rideしてもよいです。

22.2.6 Properties of the RegExp Prototype Object

RegExp prototype objectは:

  • %RegExp.prototype%です。
  • ordinary objectです。
  • RegExp instanceではなく、[[RegExpMatcher]] internal slotも、RegExp instance objectsの他のinternal slotsも持ちません。
  • valueが%Object.prototype%である[[Prototype]] internal slotを持ちます。
Note

RegExp prototype objectは自身の"valueOf" propertyを持ちません;しかし、Object prototype objectから"valueOf" propertyをinheritします。

22.2.6.1 RegExp.prototype.constructor

RegExp.prototype.constructorのinitial valueは%RegExp%です。

22.2.6.2 RegExp.prototype.exec ( string )

このmethodはstring内でregular expression patternのoccurrenceをsearchし、matchのresultsを含むArrayを返すか、stringがmatchしなかった場合はnullを返します。

これは呼び出されたとき、次のstepsを実行します:

  1. regexpthis valueとする。
  2. RequireInternalSlot(regexp, [[RegExpMatcher]])を実行する。
  3. stringを ? ToString(string) に設定する。
  4. RegExpBuiltinExec(regexp, string)を返す。

22.2.6.3 get RegExp.prototype.dotAll

RegExp.prototype.dotAllは、set accessor functionがundefinedであるaccessor propertyです。そのget accessor functionは呼び出されたとき、次のstepsを実行します:

  1. regexpthis valueとする。
  2. codeUnitをcode unit 0x0073 (LATIN SMALL LETTER S)とする。
  3. RegExpHasFlag(regexp, codeUnit)を返す。

22.2.6.4 get RegExp.prototype.flags

RegExp.prototype.flagsは、set accessor functionがundefinedであるaccessor propertyです。そのget accessor functionは呼び出されたとき、次のstepsを実行します:

  1. regexpthis valueとする。
  2. regexpがObjectでないなら、TypeError例外をthrowする。
  3. codeUnitsを新しい空のListとする。
  4. hasIndicesToBoolean(? Get(regexp, "hasIndices" ))とする。
  5. hasIndicestrueなら、code unit 0x0064 (LATIN SMALL LETTER D)をcodeUnitsへappendする。
  6. globalToBoolean(? Get(regexp, "global" ))とする。
  7. globaltrueなら、code unit 0x0067 (LATIN SMALL LETTER G)をcodeUnitsへappendする。
  8. ignoreCaseToBoolean(? Get(regexp, "ignoreCase" ))とする。
  9. ignoreCasetrueなら、code unit 0x0069 (LATIN SMALL LETTER I)をcodeUnitsへappendする。
  10. multilineToBoolean(? Get(regexp, "multiline" ))とする。
  11. multilinetrueなら、code unit 0x006D (LATIN SMALL LETTER M)をcodeUnitsへappendする。
  12. dotAllToBoolean(? Get(regexp, "dotAll" ))とする。
  13. dotAlltrueなら、code unit 0x0073 (LATIN SMALL LETTER S)をcodeUnitsへappendする。
  14. unicodeToBoolean(? Get(regexp, "unicode" ))とする。
  15. unicodetrueなら、code unit 0x0075 (LATIN SMALL LETTER U)をcodeUnitsへappendする。
  16. unicodeSetsToBoolean(? Get(regexp, "unicodeSets" ))とする。
  17. unicodeSetstrueなら、code unit 0x0076 (LATIN SMALL LETTER V)をcodeUnitsへappendする。
  18. stickyToBoolean(? Get(regexp, "sticky" ))とする。
  19. stickytrueなら、code unit 0x0079 (LATIN SMALL LETTER Y)をcodeUnitsへappendする。
  20. code unitsがList codeUnitsのelementsであるString valueを返す。codeUnitsがelementsを持たない場合、empty Stringが返される。

22.2.6.4.1 RegExpHasFlag ( regexp, codeUnit )

The abstract operation RegExpHasFlag takes arguments regexp (an ECMAScript language value) and codeUnit (a code unit) and returns either a normal completion containing either a Boolean or undefined, or a throw completion. It performs the following steps when called:

  1. regexpがObjectでないなら、TypeError例外をthrowする。
  2. regexp[[OriginalFlags]] internal slotを持たないなら、
    1. SameValue(regexp, %RegExp.prototype%)がtrueなら、undefinedを返す。
    2. TypeError例外をThrowする。
  3. flagsregexp.[[OriginalFlags]]とする。
  4. flagscodeUnitを含むなら、trueを返す。
  5. falseを返す。

22.2.6.5 get RegExp.prototype.global

RegExp.prototype.globalは、set accessor functionがundefinedであるaccessor propertyです。そのget accessor functionは呼び出されたとき、次のstepsを実行します:

  1. regexpthis valueとする。
  2. codeUnitをcode unit 0x0067 (LATIN SMALL LETTER G)とする。
  3. RegExpHasFlag(regexp, codeUnit)を返す。

22.2.6.6 get RegExp.prototype.hasIndices

RegExp.prototype.hasIndicesは、set accessor functionがundefinedであるaccessor propertyです。そのget accessor functionは呼び出されたとき、次のstepsを実行します:

  1. regexpthis valueとする。
  2. codeUnitをcode unit 0x0064 (LATIN SMALL LETTER D)とする。
  3. RegExpHasFlag(regexp, codeUnit)を返す。

22.2.6.7 get RegExp.prototype.ignoreCase

RegExp.prototype.ignoreCaseは、set accessor functionがundefinedであるaccessor propertyです。そのget accessor functionは呼び出されたとき、次のstepsを実行します:

  1. regexpthis valueとする。
  2. codeUnitをcode unit 0x0069 (LATIN SMALL LETTER I)とする。
  3. RegExpHasFlag(regexp, codeUnit)を返す。

22.2.6.8 RegExp.prototype [ %Symbol.match% ] ( string )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. regexpthis valueとする。
  2. regexpがObjectでないなら、TypeError例外をthrowする。
  3. stringを ? ToString(string) に設定する。
  4. flagsを ? ToString(? Get(regexp, "flags" )) とする。
  5. flags"g"を含まないなら、? RegExpExec(regexp, string)を返す。
  6. flags"u"を含む、またはflags"v"を含むなら、fullUnicodetrueとする;そうでなければ、fullUnicodefalseとする。
  7. Set(regexp, "lastIndex", +0𝔽, true)を実行する。
  8. arrayを ! ArrayCreate(0) とする。
  9. matchCountを0とする。
  10. 繰り返す:
    1. resultを ? RegExpExec(regexp, string) とする。
    2. resultnullなら、
      1. matchCount = 0なら、nullを返す。
      2. arrayを返す。
    3. matchStringを ? ToString(? Get(result, "0" )) とする。
    4. CreateDataPropertyOrThrow(array, ! ToString(𝔽(matchCount)), matchString)を実行する。
    5. matchStringがempty Stringなら、
      1. thisIndex(? ToLength(? Get(regexp, "lastIndex")))とする。
      2. nextIndexAdvanceStringIndex(string, thisIndex, fullUnicode)とする。
      3. Set(regexp, "lastIndex", 𝔽(nextIndex), true)を実行する。
    6. matchCountmatchCount + 1に設定する。

このmethodの"name" propertyのvalueは"[Symbol.match]"です。

Note

%Symbol.match% propertyは、regular expressionsのbasic behaviourを持つobjectsをidentifyするためにIsRegExp abstract operationによって使用されます。%Symbol.match% propertyのabsence、またはそのようなpropertyが存在するがそのvalueがBoolean coerceしてtrueにならない場合、そのobjectがregular expression objectとして使用されることを意図していないことを示します。

22.2.6.9 RegExp.prototype [ %Symbol.matchAll% ] ( string )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. regexpthis valueとする。
  2. regexpがObjectでないなら、TypeError例外をthrowする。
  3. stringを ? ToString(string) に設定する。
  4. speciesCtorを ? SpeciesConstructor(regexp, %RegExp%) とする。
  5. flagsを ? ToString(? Get(regexp, "flags" )) とする。
  6. matcherを ? Construct(speciesCtor, « regexp, flags ») とする。
  7. lastIndexを ? ToLength(? Get(regexp, "lastIndex" )) とする。
  8. Set(matcher, "lastIndex", lastIndex, true)を実行する。
  9. flags"g"を含むなら、globaltrueとする。
  10. そうでなければ、globalfalseとする。
  11. flags"u"を含む、またはflags"v"を含むなら、fullUnicodetrueとする。
  12. そうでなければ、fullUnicodefalseとする。
  13. CreateRegExpStringIterator(matcher, string, global, fullUnicode)を返す。

このmethodの"name" propertyのvalueは"[Symbol.matchAll]"です。

22.2.6.10 get RegExp.prototype.multiline

RegExp.prototype.multilineは、set accessor functionがundefinedであるaccessor propertyです。そのget accessor functionは呼び出されたとき、次のstepsを実行します:

  1. regexpthis valueとする。
  2. codeUnitをcode unit 0x006D (LATIN SMALL LETTER M)とする。
  3. RegExpHasFlag(regexp, codeUnit)を返す。

22.2.6.11 RegExp.prototype [ %Symbol.replace% ] ( string, replaceValue )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. regexpthis valueとする。
  2. regexpがObjectでないなら、TypeError例外をthrowする。
  3. stringを ? ToString(string) に設定する。
  4. stringLengthstringのlengthとする。
  5. functionalReplaceIsCallable(replaceValue)とする。
  6. functionalReplacefalseなら、
    1. replaceValueを ? ToString(replaceValue) に設定する。
  7. flagsを ? ToString(? Get(regexp, "flags" )) とする。
  8. flags"g"を含むなら、globaltrueとする;そうでなければ、globalfalseとする。
  9. globaltrueなら、
    1. Set(regexp, "lastIndex", +0𝔽, true)を実行する。
  10. resultsを新しい空のListとする。
  11. donefalseとする。
  12. donefalseである間、繰り返す
    1. resultを ? RegExpExec(regexp, string) とする。
    2. resultnullなら、
      1. donetrueに設定する。
    3. そうでなければ、
      1. resultresultsへappendする。
      2. globalfalseなら、
        1. donetrueに設定する。
      3. そうでなければ、
        1. matchStringを ? ToString(? Get(result, "0" )) とする。
        2. matchStringがempty Stringなら、
          1. thisIndex(? ToLength(? Get(regexp, "lastIndex")))とする。
          2. flags"u"を含む、またはflags"v"を含むなら、fullUnicodetrueとする;そうでなければ、fullUnicodefalseとする。
          3. nextIndexAdvanceStringIndex(string, thisIndex, fullUnicode)とする。
          4. Set(regexp, "lastIndex", 𝔽(nextIndex), true)を実行する。
  13. accumulatedResultをempty Stringとする。
  14. nextSourcePositionを0とする。
  15. resultsの各要素resultについて、以下を行う
    1. resultLengthを ? LengthOfArrayLike(result) とする。
    2. capturesCountmax(resultLength - 1, 0)とする。
    3. matchedを ? ToString(? Get(result, "0" )) とする。
    4. matchLengthmatchedのlengthとする。
    5. positionを ? ToIntegerOrInfinity(? Get(result, "index" )) とする。
    6. positionを、0とstringLengthの間にclampingしたresultに設定する。
    7. capturesを新しい空のListとする。
    8. captureNumberを1とする。
    9. captureNumbercapturesCountの間、繰り返す
      1. captureを ? Get(result, ! ToString(𝔽(captureNumber))) とする。
      2. captureundefinedでないなら、
        1. captureを ? ToString(capture) に設定する。
      3. capturecapturesへappendする。
      4. NOTE: captureNumber = 1のとき、preceding stepはfirst elementをcapturesへputする(index 0に)。より一般に、captureNumberth capture(captureNumberth set of capturing parenthesesによってcapturedされたcharacters)はcaptures[captureNumber - 1]にある。
      5. captureNumbercaptureNumber + 1に設定する。
    10. namedCapturesを ? Get(result, "groups" ) とする。
    11. functionalReplacetrueなら、
      1. replacerArgsを« matched »、captures、および« 𝔽(position), string »のlist-concatenationとする。
      2. namedCapturesundefinedでないなら、
        1. namedCapturesreplacerArgsへappendする。
      3. replacementValueを ? Call(replaceValue, undefined, replacerArgs) とする。
      4. replacementStringを ? ToString(replacementValue) とする。
    12. そうでなければ、
      1. namedCapturesundefinedでないなら、
        1. namedCapturesを ? ToObject(namedCaptures) に設定する。
      2. replacementStringを ? GetSubstitution(matched, string, position, captures, namedCaptures, replaceValue) とする。
    13. positionnextSourcePositionなら、
      1. NOTE: positionは通常backwardsにmoveすべきではない。そうなる場合、それはill-behaving RegExp subclass、またはregexpのglobal flagやその他のcharacteristicsをchangeするためのaccess triggered side-effectの使用を示す。そのようなcasesでは、corresponding substitutionはignoredされる。
      2. accumulatedResultを、accumulatedResultstringnextSourcePositionからpositionまでのsubstring、およびreplacementStringstring-concatenationに設定する。
      3. nextSourcePositionposition + matchLengthに設定する。
  16. nextSourcePositionstringLengthなら、accumulatedResultを返す。
  17. accumulatedResultstringnextSourcePositionからのsubstringstring-concatenationを返す。

このmethodの"name" propertyのvalueは"[Symbol.replace]"です。

22.2.6.12 RegExp.prototype [ %Symbol.search% ] ( string )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. regexpthis valueとする。
  2. regexpがObjectでないなら、TypeError例外をthrowする。
  3. stringを ? ToString(string) に設定する。
  4. previousLastIndexを ? Get(regexp, "lastIndex" ) とする。
  5. previousLastIndex+0𝔽でないなら、
    1. Set(regexp, "lastIndex", +0𝔽, true)を実行する。
  6. resultを ? RegExpExec(regexp, string) とする。
  7. currentLastIndexを ? Get(regexp, "lastIndex" ) とする。
  8. SameValue(currentLastIndex, previousLastIndex)がfalseなら、
    1. Set(regexp, "lastIndex", previousLastIndex, true)を実行する。
  9. resultnullなら、-1𝔽を返す。
  10. Get(result, "index" )を返す。

このmethodの"name" propertyのvalueは"[Symbol.search]"です。

Note

このRegExp objectの"lastIndex"および"global" propertiesのvalueは、searchをperformするときignoredされます。"lastIndex" propertyはunchangedのままです。

22.2.6.13 get RegExp.prototype.source

RegExp.prototype.sourceは、set accessor functionがundefinedであるaccessor propertyです。そのget accessor functionは呼び出されたとき、次のstepsを実行します:

  1. regexpthis valueとする。
  2. regexpがObjectでないなら、TypeError例外をthrowする。
  3. regexp[[OriginalSource]] internal slotを持たないなら、
    1. SameValue(regexp, %RegExp.prototype%)がtrueなら、"(?:)"を返す。
    2. TypeError例外をThrowする。
  4. Assert: regexp[[OriginalFlags]] internal slotを持つ。
  5. sourceregexp.[[OriginalSource]]とする。
  6. flagsregexp.[[OriginalFlags]]とする。
  7. EscapeRegExpPattern(source, flags)を返す。

22.2.6.13.1 EscapeRegExpPattern ( pattern, flags )

The abstract operation EscapeRegExpPattern takes arguments pattern (a String) and flags (a String) and returns a String. It performs the following steps when called:

  1. flags"v"を含むなら、
    1. patternSymbolPattern[+UnicodeMode, +UnicodeSetsMode]とする。
  2. そうでなく、flags"u"を含むなら、
    1. patternSymbolPattern[+UnicodeMode, ~UnicodeSetsMode]とする。
  3. そうでなければ、
    1. patternSymbolPattern[~UnicodeMode, ~UnicodeSetsMode]とする。
  4. escapedPatternを、UTF-16 encoded Unicode code points(6.1.4)としてinterpretedされたpatternにequivalentなpatternSymbolのformのStringとする。この中では、certain code pointsが以下でdescribedされる通りescapedされます。escapedPatternpatternとdifferしてもよいしdifferしなくてもよい;しかし、escapedPatternpatternSymbolとしてevaluatingすることでresultするAbstract Closureは、constructed objectの[[RegExpMatcher]] internal slotによってgivenされるAbstract Closureとidenticallyにbehaveしなければなりません。このabstract operationをpatternおよびflagsのsame valuesでmultiple callsすると、identical resultsをproduceしなければなりません。
  5. pattern内にoccurringするcode points /または任意のLineTerminatorは、" / "ではなく"/"escapedPattern"/"、およびflagsstring-concatenationが(appropriate lexical contextにおいて)constructed regular expressionとidenticallyにbehaveするRegularExpressionLiteralとしてparseできることをensureするため、必要に応じてescapedPattern内でescapedされなければなりません。例えば、pattern"/"なら、escapedPattern"\/"または"\u002F"などであり得ますが、"/"ではあり得ません。なぜなら、flagsがfollowする///RegularExpressionLiteralではなくSingleLineCommentとしてparseされるからです。patternがempty Stringなら、このspecificationはescapedPattern"(?:)"とすることで満たされ得ます。
  6. escapedPatternを返す。
Note

similar namesを持つにもかかわらず、RegExp.escapeとEscapeRegExpPatternはsimilar actionsをperformしません。前者はpatternの内側でrepresentationするためにstringをescapeし、このfunctionはstringとしてrepresentationするためにpatternをescapeします。

22.2.6.14 RegExp.prototype [ %Symbol.split% ] ( string, limit )

Note 1

このmethodは、stringをStringへconvertingしたresultのsubstringsがstoredされたArrayを返します。substringsは、this value regular expressionのmatchesをleft to rightにsearchすることでdeterminedされます;これらのoccurrencesはreturned array内のいかなるStringのpartでもありませんが、String valueをdivide upする役割を果たします。

this valueはempty regular expression、またはempty Stringにmatchできるregular expressionであり得ます。このcaseでは、regular expressionはinput Stringのbeginningまたはendにあるempty substringにはmatchせず、previous separator matchのendにあるempty substringにもmatchしません。(例えば、regular expressionがempty Stringにmatchする場合、Stringはindividual code unit elementsへsplit upされます;result arrayのlengthはStringのlengthに等しく、各substringはone code unitを含みます。)given index of the Stringにおけるfirst matchのみがconsideredされます。backtrackingによってそのindexでnon-empty substring matchがyieldされ得る場合であってもです。(例えば、/a*?/[Symbol.split]("ab")はarray ["a", "b"]へevaluatesされ、一方/a*/[Symbol.split]("ab")はarray ["","b"]へevaluatesされます。)

stringがempty Stringである(またはそれへconvertsされる)場合、resultはregular expressionがempty Stringにmatchできるかどうかに依存します。matchできる場合、result arrayはelementsを含みません。そうでなければ、result arrayはone elementを含み、それはempty Stringです。

regular expressionがcapturing parenthesesを含む場合、separatorがmatchedされるたびに、capturing parenthesesのresults(任意のundefined resultsを含む)がoutput arrayへsplicedされます。例えば、

/<(\/)?([^<>]+)>/[Symbol.split]("A<B>bold</B>and<CODE>coded</CODE>")

はarrayへevaluatesされます:

["A", undefined, "B", "bold", "/", "B", "and", undefined, "CODE", "coded", "/", "CODE", ""]

limitundefinedでない場合、output arrayはlimit elements以下を含むようにtruncatedされます。

このmethodは呼び出されたとき、次のstepsを実行します:

  1. regexpthis valueとする。
  2. regexpがObjectでないなら、TypeError例外をthrowする。
  3. stringを ? ToString(string) に設定する。
  4. speciesCtorを ? SpeciesConstructor(regexp, %RegExp%) とする。
  5. flagsを ? ToString(? Get(regexp, "flags" )) とする。
  6. flags"u"を含む、またはflags"v"を含むなら、unicodeMatchingtrueとする。
  7. そうでなければ、unicodeMatchingfalseとする。
  8. flags"y"を含むなら、newFlagsflagsとする。
  9. そうでなければ、newFlagsflags"y"string-concatenationとする。
  10. splitterを ? Construct(speciesCtor, « regexp, newFlags ») とする。
  11. arrayを ! ArrayCreate(0) とする。
  12. lengthAを0とする。
  13. limitundefinedなら、limを232 - 1とする;そうでなければ、lim(? ToUint32(limit))とする。
  14. lim = 0なら、arrayを返す。
  15. stringがempty Stringなら、
    1. matchResultを ? RegExpExec(splitter, string) とする。
    2. matchResultnullでないなら、arrayを返す。
    3. CreateDataPropertyOrThrow(array, "0", string)を実行する。
    4. arrayを返す。
  16. sizestringのlengthとする。
  17. lastMatchEndを0とする。
  18. searchIndexlastMatchEndとする。
  19. searchIndex < sizeの間、繰り返す
    1. Set(splitter, "lastIndex", 𝔽(searchIndex), true)を実行する。
    2. matchResultを ? RegExpExec(splitter, string) とする。
    3. matchResultnullなら、
      1. searchIndexAdvanceStringIndex(string, searchIndex, unicodeMatching)に設定する。
    4. そうでなければ、
      1. matchEnd(? ToLength(? Get(splitter, "lastIndex")))とする。
      2. matchEndmin(matchEnd, size)に設定する。
      3. matchEnd = lastMatchEndなら、
        1. searchIndexAdvanceStringIndex(string, searchIndex, unicodeMatching)に設定する。
      4. そうでなければ、
        1. substringstringlastMatchEndからsearchIndexまでのsubstringとする。
        2. CreateDataPropertyOrThrow(array, ! ToString(𝔽(lengthA)), substring)を実行する。
        3. lengthAlengthA + 1に設定する。
        4. lengthA = limなら、arrayを返す。
        5. lastMatchEndmatchEndに設定する。
        6. numberOfCapturesを ? LengthOfArrayLike(matchResult) とする。
        7. numberOfCapturesmax(numberOfCaptures - 1, 0)に設定する。
        8. captureIndexを1とする。
        9. captureIndexnumberOfCapturesの間、繰り返す
          1. nextCaptureを ? Get(matchResult, ! ToString(𝔽(captureIndex))) とする。
          2. CreateDataPropertyOrThrow(array, ! ToString(𝔽(lengthA)), nextCapture)を実行する。
          3. captureIndexcaptureIndex + 1に設定する。
          4. lengthAlengthA + 1に設定する。
          5. lengthA = limなら、arrayを返す。
        10. searchIndexlastMatchEndに設定する。
  20. substringstringlastMatchEndからsizeまでのsubstringとする。
  21. CreateDataPropertyOrThrow(array, ! ToString(𝔽(lengthA)), substring)を実行する。
  22. arrayを返す。

このmethodの"name" propertyのvalueは"[Symbol.split]"です。

Note 2

このmethodは、このRegExp objectの"global"および"sticky" propertiesのvalueをignoreします。

22.2.6.15 get RegExp.prototype.sticky

RegExp.prototype.stickyは、set accessor functionがundefinedであるaccessor propertyです。そのget accessor functionは呼び出されたとき、次のstepsを実行します:

  1. regexpthis valueとする。
  2. codeUnitをcode unit 0x0079 (LATIN SMALL LETTER Y)とする。
  3. RegExpHasFlag(regexp, codeUnit)を返す。

22.2.6.16 RegExp.prototype.test ( string )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. regexpthis valueとする。
  2. regexpがObjectでないなら、TypeError例外をthrowする。
  3. stringを ? ToString(string) に設定する。
  4. matchを ? RegExpExec(regexp, string) とする。
  5. matchnullなら、falseを返す。
  6. trueを返す。

22.2.6.17 RegExp.prototype.toString ( )

  1. regexpthis valueとする。
  2. regexpがObjectでないなら、TypeError例外をthrowする。
  3. patternを ? ToString(? Get(regexp, "source" )) とする。
  4. flagsを ? ToString(? Get(regexp, "flags" )) とする。
  5. result"/"pattern"/"、およびflagsstring-concatenationとする。
  6. resultを返す。
Note

returned Stringは、このobjectとsame behaviourを持つanother RegExp objectへevaluatesされるRegularExpressionLiteralのformを持ちます。

22.2.6.18 get RegExp.prototype.unicode

RegExp.prototype.unicodeは、set accessor functionがundefinedであるaccessor propertyです。そのget accessor functionは呼び出されたとき、次のstepsを実行します:

  1. regexpthis valueとする。
  2. codeUnitをcode unit 0x0075 (LATIN SMALL LETTER U)とする。
  3. RegExpHasFlag(regexp, codeUnit)を返す。

22.2.6.19 get RegExp.prototype.unicodeSets

RegExp.prototype.unicodeSetsは、set accessor functionがundefinedであるaccessor propertyです。そのget accessor functionは呼び出されたとき、次のstepsを実行します:

  1. regexpthis valueとする。
  2. codeUnitをcode unit 0x0076 (LATIN SMALL LETTER V)とする。
  3. RegExpHasFlag(regexp, codeUnit)を返す。

22.2.7 Abstract Operations for RegExp Matching

22.2.7.1 RegExpExec ( regexp, string )

The abstract operation RegExpExec takes arguments regexp (an Object) and string (a String) and returns either a normal completion containing either an Object or null, or a throw completion. It performs the following steps when called:

  1. execを ? Get(regexp, "exec") とする。
  2. IsCallable(exec)がtrueなら、
    1. resultを ? Call(exec, regexp, « string ») とする。
    2. resultがObjectでなく、かつresultnullでないなら、TypeError例外をthrowする。
    3. resultを返す。
  3. RequireInternalSlot(regexp, [[RegExpMatcher]])を実行する。
  4. RegExpBuiltinExec(regexp, string)を返す。
Note

callableな"exec" propertyが見つからない場合、このalgorithmはbuilt-in RegExp matching algorithmの使用を試みることへfall backします。これは、regular expressionsを使用するmost built-in algorithmsが"exec"のdynamic property lookupをperformしなかったprior editions向けに書かれたcodeに対してcompatible behaviourを提供します。

22.2.7.2 RegExpBuiltinExec ( regexp, string )

The abstract operation RegExpBuiltinExec takes arguments regexp (an initialized RegExp instance) and string (a String) and returns either a normal completion containing either an Array exotic object or null, or a throw completion. It performs the following steps when called:

  1. lengthstringのlengthとする。
  2. lastIndex(? ToLength(! Get(regexp, "lastIndex")))とする。
  3. flagsregexp.[[OriginalFlags]]とする。
  4. flags"g"を含むなら、globaltrueとする;そうでなければ、globalfalseとする。
  5. flags"y"を含むなら、stickytrueとする;そうでなければ、stickyfalseとする。
  6. flags"d"を含むなら、hasIndicestrueとする;そうでなければ、hasIndicesfalseとする。
  7. globalfalseであり、かつstickyfalseなら、lastIndexを0に設定する。
  8. matcherregexp.[[RegExpMatcher]]とする。
  9. flags"u"を含む、またはflags"v"を含むなら、fullUnicodetrueとする;そうでなければ、fullUnicodefalseとする。
  10. matchSucceededfalseとする。
  11. fullUnicodetrueなら、inputStringToCodePoints(string)とする;そうでなければ、inputを、そのelementsがstringのelementsであるcode unitsであるListとする。
  12. NOTE: inputの各elementはcharacterであるとconsiderされる。
  13. matchSucceededfalseである間、繰り返す
    1. lastIndex > lengthなら、
      1. globaltrueまたはstickytrueなら、
        1. Set(regexp, "lastIndex", +0𝔽, true)を実行する。
      2. nullを返す。
    2. inputIndexを、stringのelement lastIndexからobtainedされたcharacterのinput内のindexとする。
    3. resultmatcher(input, inputIndex)とする。
    4. resultfailureなら、
      1. stickytrueなら、
        1. Set(regexp, "lastIndex", +0𝔽, true)を実行する。
        2. nullを返す。
      2. lastIndexAdvanceStringIndex(string, lastIndex, fullUnicode)に設定する。
    5. そうでなければ、
      1. Assert: resultMatchStateである。
      2. matchSucceededtrueに設定する。
  14. endIndexresult.[[EndIndex]]とする。
  15. fullUnicodetrueなら、endIndexGetStringIndex(string, endIndex)に設定する。
  16. globaltrueまたはstickytrueなら、
    1. Set(regexp, "lastIndex", 𝔽(endIndex), true)を実行する。
  17. capturingGroupsCountresult.[[Captures]]内のelementsの数とする。
  18. Assert: capturingGroupsCount = regexp.[[RegExpRecord]].[[CapturingGroupsCount]]である。
  19. Assert: capturingGroupsCount < 232 - 1である。
  20. arrayを ! ArrayCreate(capturingGroupsCount + 1) とする。
  21. Assert: array"length" propertyのmathematical valuecapturingGroupsCount + 1である。
  22. CreateDataPropertyOrThrow(array, "index", 𝔽(lastIndex))を実行する。
  23. CreateDataPropertyOrThrow(array, "input", string)を実行する。
  24. matchMatch Record { [[StartIndex]]: lastIndex, [[EndIndex]]: endIndex }とする。
  25. indicesを新しい空のListとする。
  26. groupNamesを新しい空のListとする。
  27. matchindicesへappendする。
  28. matchedSubstringGetMatchString(string, match)とする。
  29. CreateDataPropertyOrThrow(array, "0", matchedSubstring)を実行する。
  30. regexpが任意のGroupNameを含むなら、
    1. groupsOrdinaryObjectCreate(null)とする。
    2. hasGroupstrueとする。
  31. そうでなければ、
    1. groupsundefinedとする。
    2. hasGroupsfalseとする。
  32. CreateDataPropertyOrThrow(array, "groups", groups)を実行する。
  33. matchedGroupNamesを新しい空のListとする。
  34. 1 ≤ icapturingGroupsCountである各integer iについて、ascending orderで、以下を行う
    1. captureresult.[[Captures]]ith elementとする。
    2. captureundefinedなら、
      1. capturedValueundefinedとする。
      2. undefinedindicesへappendする。
    3. そうでなければ、
      1. captureStartcapture.[[StartIndex]]とする。
      2. captureEndcapture.[[EndIndex]]とする。
      3. fullUnicodetrueなら、
        1. captureStartGetStringIndex(string, captureStart)に設定する。
        2. captureEndGetStringIndex(string, captureEnd)に設定する。
      4. captureRecordMatch Record { [[StartIndex]]: captureStart, [[EndIndex]]: captureEnd }とする。
      5. capturedValueGetMatchString(string, captureRecord)とする。
      6. captureRecordindicesへappendする。
    4. CreateDataPropertyOrThrow(array, ! ToString(𝔽(i)), capturedValue)を実行する。
    5. regexpith captureがGroupNameでdefinedされていたなら、
      1. groupNameをそのGroupNameCapturingGroupNameとする。
      2. matchedGroupNamesgroupNameを含むなら、
        1. Assert: capturedValueundefinedである。
        2. undefinedgroupNamesへappendする。
      3. そうでなければ、
        1. capturedValueundefinedでないなら、groupNamematchedGroupNamesへappendする。
        2. NOTE: groupNameとnamedされたmultiple groupsが存在する場合、groupsはこの時点ですでにgroupName propertyを持っている可能性がある。しかし、groupsは、そのpropertiesがすべてwritable data propertiesであるordinary objectであるため、CreateDataPropertyOrThrowへのcallはそれでもsucceedすることがguaranteedされる。
        3. CreateDataPropertyOrThrow(groups, groupName, capturedValue)を実行する。
        4. groupNamegroupNamesへappendする。
    6. そうでなければ、
      1. undefinedgroupNamesへappendする。
  35. hasIndicestrueなら、
    1. indicesArrayMakeMatchIndicesIndexPairArray(string, indices, groupNames, hasGroups)とする。
    2. CreateDataPropertyOrThrow(array, "indices", indicesArray)を実行する。
  36. arrayを返す。

22.2.7.3 AdvanceStringIndex ( string, index, unicode )

The abstract operation AdvanceStringIndex takes arguments string (a String), index (a non-negative integer), and unicode (a Boolean) and returns a non-negative integer. It performs the following steps when called:

  1. Assert: index ≤ 253 - 1である。
  2. unicodefalseなら、index + 1を返す。
  3. lengthstringのlengthとする。
  4. index + 1 ≥ lengthなら、index + 1を返す。
  5. codePointCodePointAt(string, index)とする。
  6. index + codePoint.[[CodeUnitCount]]を返す。

22.2.7.4 GetStringIndex ( string, codePointIndex )

The abstract operation GetStringIndex takes arguments string (a String) and codePointIndex (a non-negative integer) and returns a non-negative integer. これは、6.1.4でdescribedされる通り、stringをUTF-16 encoded code pointsのsequenceとしてinterpretし、そのようなindexが存在する場合、code point index codePointIndexに対応するcode unit indexを返します。そうでなければ、stringのlengthを返します。 It performs the following steps when called:

  1. stringがempty Stringなら、0を返す。
  2. lengthstringのlengthとする。
  3. codeUnitCountを0とする。
  4. codePointCountを0とする。
  5. codeUnitCount < lengthの間、繰り返す
    1. codePointCount = codePointIndexなら、codeUnitCountを返す。
    2. codePointCodePointAt(string, codeUnitCount)とする。
    3. codeUnitCountcodeUnitCount + codePoint.[[CodeUnitCount]]に設定する。
    4. codePointCountcodePointCount + 1に設定する。
  6. lengthを返す。

22.2.7.5 Match Records

Match Recordは、regular expression matchまたはcaptureのstartおよびend indicesをencapsulateするために使用されるRecord valueです。

Match RecordsはTable 68にlistedされたfieldsを持ちます。

Table 68: Match Record Fields
Field Name Value Meaning
[[StartIndex]] a non-negative integer matchがbeginする(inclusive)stringのstartからのcode unitsの数。
[[EndIndex]] an integer[[StartIndex]] matchがendする(exclusive)stringのstartからのcode unitsの数。

22.2.7.6 GetMatchString ( string, match )

The abstract operation GetMatchString takes arguments string (a String) and match (a Match Record) and returns a String. It performs the following steps when called:

  1. Assert: match.[[StartIndex]]match.[[EndIndex]]stringのlengthである。
  2. stringmatch.[[StartIndex]]からmatch.[[EndIndex]]までのsubstringを返す。

22.2.7.7 GetMatchIndexPair ( string, match )

The abstract operation GetMatchIndexPair takes arguments string (a String) and match (a Match Record) and returns an Array. It performs the following steps when called:

  1. Assert: match.[[StartIndex]]match.[[EndIndex]]stringのlengthである。
  2. CreateArrayFromList𝔽(match.[[StartIndex]]), 𝔽(match.[[EndIndex]]) »)を返す。

22.2.7.8 MakeMatchIndicesIndexPairArray ( string, indices, groupNames, hasGroups )

The abstract operation MakeMatchIndicesIndexPairArray takes arguments string (a String), indices (a List of either Match Records or undefined), groupNames (a List of either Strings or undefined), and hasGroups (a Boolean) and returns an Array. It performs the following steps when called:

  1. nindices内のelementsの数とする。
  2. Assert: n < 232 - 1である。
  3. Assert: groupNamesn - 1個のelementsを持つ。
  4. NOTE: groupNames Listindices[1]からstartingしてindices Listとalignedされたelementsを含む。
  5. arrayを ! ArrayCreate(n) とする。
  6. hasGroupstrueなら、
    1. groupsOrdinaryObjectCreate(null)とする。
  7. そうでなければ、
    1. groupsundefinedとする。
  8. CreateDataPropertyOrThrow(array, "groups", groups)を実行する。
  9. 0 ≤ i < nである各integer iについて、ascending orderで、以下を行う
    1. matchIndicesindices[i]とする。
    2. matchIndicesundefinedでないなら、
      1. matchIndexPairGetMatchIndexPair(string, matchIndices)とする。
    3. そうでなければ、
      1. matchIndexPairundefinedとする。
    4. CreateDataPropertyOrThrow(array, ! ToString(𝔽(i)), matchIndexPair)を実行する。
    5. i > 0なら、
      1. namegroupNames[i - 1]とする。
      2. nameundefinedでないなら、
        1. Assert: groupsundefinedでない。
        2. NOTE: nameとnamedされたmultiple groupsが存在する場合、groupsはこの時点ですでにname propertyを持っている可能性がある。しかし、groupsは、そのpropertiesがすべてwritable data propertiesであるordinary objectであるため、CreateDataPropertyOrThrowへのcallはそれでもsucceedすることがguaranteedされる。
        3. CreateDataPropertyOrThrow(groups, name, matchIndexPair)を実行する。
  10. arrayを返す。

22.2.8 Properties of RegExp Instances

RegExp instancesはRegExp prototype objectからpropertiesをinheritするordinary objectsです。RegExp instancesはinternal slots [[OriginalSource]], [[OriginalFlags]], [[RegExpRecord]], および[[RegExpMatcher]]を持ちます。[[RegExpMatcher]] internal slotのvalueは、RegExp objectのPatternAbstract Closure representationです。

Note

ECMAScript 2015より前は、RegExp instancesはown data properties "source""global""ignoreCase"、および"multiline"を持つものとしてspecifiedされていました。現在、それらのpropertiesはRegExp.prototypeaccessor propertiesとしてspecifiedされています。

RegExp instancesはまた次のpropertyを持ちます:

22.2.8.1 lastIndex

"lastIndex" propertyのvalueは、next matchをstartするString indexをspecifyします。これは使用時にintegral Numberへcoercedされます(22.2.7.2を参照)。このpropertyはattributes { [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }を持たなければなりません。

22.2.9 RegExp String Iterator Objects

RegExp String Iteratorは、some specific RegExp instance objectに対してmatchingしながら、some specific String instance object上のspecific iterationを表すobjectです。RegExp String Iterator objectsにはnamed constructorは存在しません。代わりに、RegExp String Iterator objectsはRegExp instance objectsのcertain methodsを呼び出すことで作成されます。

22.2.9.1 CreateRegExpStringIterator ( regexp, string, global, fullUnicode )

The abstract operation CreateRegExpStringIterator takes arguments regexp (an Object), string (a String), global (a Boolean), and fullUnicode (a Boolean) and returns an Object. It performs the following steps when called:

  1. iteratorOrdinaryObjectCreate(%RegExpStringIteratorPrototype%, « [[IteratingRegExp]], [[IteratedString]], [[Global]], [[Unicode]], [[Done]] »)とする。
  2. iterator.[[IteratingRegExp]]regexpに設定する。
  3. iterator.[[IteratedString]]stringに設定する。
  4. iterator.[[Global]]globalに設定する。
  5. iterator.[[Unicode]]fullUnicodeに設定する。
  6. iterator.[[Done]]falseに設定する。
  7. iteratorを返す。

22.2.9.2 The %RegExpStringIteratorPrototype% Object

%RegExpStringIteratorPrototype% objectは:

22.2.9.2.1 %RegExpStringIteratorPrototype%.next ( )

  1. iteratorObjthis valueとする。
  2. iteratorObjがObjectでないなら、TypeError例外をthrowする。
  3. iteratorObjRegExp String Iterator Object Instanceのすべてのinternal slotsを持たないなら(22.2.9.3を参照)、TypeError例外をthrowする。
  4. iteratorObj.[[Done]]trueなら、
    1. CreateIteratorResultObject(undefined, true)を返す。
  5. regexpiteratorObj.[[IteratingRegExp]]とする。
  6. stringiteratorObj.[[IteratedString]]とする。
  7. globaliteratorObj.[[Global]]とする。
  8. fullUnicodeiteratorObj.[[Unicode]]とする。
  9. matchを ? RegExpExec(regexp, string) とする。
  10. matchnullなら、
    1. iteratorObj.[[Done]]trueに設定する。
    2. CreateIteratorResultObject(undefined, true)を返す。
  11. globalfalseなら、
    1. iteratorObj.[[Done]]trueに設定する。
    2. CreateIteratorResultObject(match, false)を返す。
  12. matchStringを ? ToString(? Get(match, "0")) とする。
  13. matchStringがempty Stringなら、
    1. thisIndex(? ToLength(? Get(regexp, "lastIndex")))とする。
    2. nextIndexAdvanceStringIndex(string, thisIndex, fullUnicode)とする。
    3. Set(regexp, "lastIndex", 𝔽(nextIndex), true)を実行する。
  14. CreateIteratorResultObject(match, false)を返す。

22.2.9.2.2 %RegExpStringIteratorPrototype% [ %Symbol.toStringTag% ]

%Symbol.toStringTag% propertyのinitial valueはString value "RegExp String Iterator"です。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }を持ちます。

22.2.9.3 Properties of RegExp String Iterator Instances

RegExp String Iterator instancesは、%RegExpStringIteratorPrototype% intrinsic objectからpropertiesをinheritするordinary objectsです。RegExp String Iterator instancesは、Table 69にlistedされたinternal slotsを持ってinitiallyに作成されます。

Table 69: Internal Slots of RegExp String Iterator Instances
Internal Slot Type Description
[[IteratingRegExp]] an Object iterationに使用されるregular expression。IsRegExp([[IteratingRegExp]])はinitially trueです。
[[IteratedString]] a String iterateされているString value。
[[Global]] a Boolean [[IteratingRegExp]]がglobalであるかどうかを示します。
[[Unicode]] a Boolean [[IteratingRegExp]]がUnicode modeであるかどうかを示します。
[[Done]] a Boolean iterationがcompleteしているかどうかを示します。