22 Text Processing

22.1 String Objects

22.1.1 The String Constructor

String constructor는:

  • %String%입니다.
  • global object"String" property의 initial value입니다.
  • constructor로 called될 때 new String object를 create하고 initialize합니다.
  • constructor가 아니라 function으로 called될 때 type conversion을 수행합니다.
  • class definition의 extends clause의 value로 사용될 수 있습니다. specified String behaviour를 inherit하려는 subclass constructor[[StringData]] internal slot을 가진 subclass instance를 create하고 initialize하기 위해 String constructor에 대한 super call을 include해야 합니다.

22.1.1.1 String ( value )

이 function은 called될 때 following 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을 가집니다.
  • 다음 property를 가집니다:

22.1.2.1 String.fromCharCode ( ...codeUnits )

이 function은 rest parameter codeUnits를 form하는 any number의 arguments와 함께 called될 수 있습니다.

called될 때 following steps를 수행합니다:

  1. result를 empty String으로 둔다.
  2. codeUnits의 각 element 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를 form하는 any number의 arguments와 함께 called될 수 있습니다.

called될 때 following steps를 수행합니다:

  1. result를 empty String으로 둔다.
  2. codePoints의 각 element next에 대해, 다음을 수행한다.
    1. nextCP를 ? ToNumber(next)로 둔다.
    2. nextCPintegral Number가 아니면, RangeError exception을 throw한다.
    3. (nextCP) < 0 또는 (nextCP) > 0x10FFFF이면, RangeError exception을 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와 함께 called될 수 있습니다. first argument는 template이고 나머지 arguments는 List substitutions를 form합니다.

called될 때 following 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. Repeat,
    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으로 use되도록 intended됩니다. 그렇게 called될 때, first argument는 well formed template object이고 rest parameter는 substitution values를 contain합니다.

22.1.3 Properties of the String Prototype Object

String prototype object는:

  • %String.prototype%입니다.
  • String exotic object이며 such objects에 대해 specified된 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을 가집니다.

explicitly 달리 stated되지 않는 한, 아래에 defined된 String prototype object의 methods는 generic하지 않으며, 이들에게 passed되는 this value는 String value 또는 String value로 initialized된 [[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는 this object를 String으로 converting한 result인 String value 안에서 index position의 code unit을 contain하는 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는 called될 때 following 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는 intentionally generic입니다; this value가 String object일 것을 require하지 않습니다. 따라서 method로 사용하기 위해 other kinds of objects에 transferred될 수 있습니다.

22.1.3.3 String.prototype.charCodeAt ( position )

Note 1

이 method는 this object를 String으로 converting한 result인 String 안에서 index position의 code unit의 numeric value인 Number(216보다 작은 non-negative integral Number)를 반환합니다. 해당 index에 element가 없으면 result는 NaN입니다.

이 method는 called될 때 following 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는 intentionally generic입니다; this value가 String object일 것을 require하지 않습니다. 따라서 method로 사용하기 위해 other kinds of objects에 transferred될 수 있습니다.

22.1.3.4 String.prototype.codePointAt ( position )

Note 1

이 method는 this object를 String으로 converting한 result인 String 안에서 index position의 string element에서 starting하는 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는 called될 때 following 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는 intentionally generic입니다; this value가 String object일 것을 require하지 않습니다. 따라서 method로 사용하기 위해 other kinds of objects에 transferred될 수 있습니다.

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

Note 1

이 method가 called되면 this value의 code units(String으로 converted됨) 뒤에 각 argument가 String으로 converted된 code units가 followed되는 String value를 반환합니다. result는 String value이며, String object가 아닙니다.

이 method는 called될 때 following steps를 수행합니다:

  1. thisValuethis value로 둔다.
  2. RequireObjectCoercible(thisValue)를 수행한다.
  3. string을 ? ToString(thisValue)로 둔다.
  4. resultstring으로 둔다.
  5. args의 각 element next에 대해, 다음을 수행한다.
    1. nextString을 ? ToString(next)로 둔다.
    2. resultresultnextStringstring-concatenation으로 설정한다.
  6. result를 반환한다.

이 method의 "length" property는 1𝔽입니다.

Note 2

이 method는 intentionally generic입니다; this value가 String object일 것을 require하지 않습니다. 따라서 method로 사용하기 위해 other kinds of objects에 transferred될 수 있습니다.

22.1.3.6 String.prototype.constructor

String.prototype.constructor의 initial value는 %String%입니다.

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

이 method는 called될 때 following steps를 수행합니다:

  1. thisValuethis value로 둔다.
  2. RequireObjectCoercible(thisValue)를 수행한다.
  3. string을 ? ToString(thisValue)로 둔다.
  4. isRegexp를 ? IsRegExp(searchString)로 둔다.
  5. isRegexptrue이면, TypeError exception을 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하는 것은, future editions가 such argument values를 allow하는 extensions를 define할 수 있도록 specified되었습니다.

Note 2

이 method는 intentionally generic입니다; this value가 String object일 것을 require하지 않습니다. 따라서 method로 사용하기 위해 other kinds of objects에 transferred될 수 있습니다.

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

이 method는 called될 때 following steps를 수행합니다:

  1. thisValuethis value로 둔다.
  2. RequireObjectCoercible(thisValue)를 수행한다.
  3. string을 ? ToString(thisValue)로 둔다.
  4. isRegexp를 ? IsRegExp(searchString)로 둔다.
  5. isRegexptrue이면, TypeError exception을 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이 this object를 String으로 converting한 result의 substring으로, position 이상인 one or more indices에 appear하면 이 function은 true를 반환합니다; otherwise false를 반환합니다. positionundefined이면 String 전체를 search하도록 0이 assumed됩니다.

Note 2

first argument가 RegExp이면 exception을 throw하는 것은, future editions가 such argument values를 allow하는 extensions를 define할 수 있도록 specified되었습니다.

Note 3

이 method는 intentionally generic입니다; this value가 String object일 것을 require하지 않습니다. 따라서 method로 사용하기 위해 other kinds of objects에 transferred될 수 있습니다.

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

Note 1

searchString이 this object를 String으로 converting한 result의 substring으로, position 이상인 one or more indices에 appear하면, smallest such index가 returned됩니다; otherwise -1𝔽가 returned됩니다. positionundefined이면 String 전체를 search하도록 +0𝔽가 assumed됩니다.

이 method는 called될 때 following 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는 intentionally generic입니다; this value가 String object일 것을 require하지 않습니다. 따라서 method로 사용하기 위해 other kinds of objects에 transferred될 수 있습니다.

22.1.3.10 String.prototype.isWellFormed ( )

이 method는 called될 때 following 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이 this object를 String으로 converting한 result의 substring으로 position 이하인 one or more indices에 appear하면, greatest such index가 returned됩니다; otherwise -1𝔽가 returned됩니다. positionundefined이면, String value의 length가 assumed되어 String 전체를 search합니다.

이 method는 called될 때 following 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는 intentionally generic입니다; this value가 String object일 것을 require하지 않습니다. 따라서 method로 사용하기 위해 other kinds of objects에 transferred될 수 있습니다.

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

ECMA-402 Internationalization API를 include하는 ECMAScript implementation은 ECMA-402 specification에 specified된 대로 이 method를 implement해야 합니다. ECMAScript implementation이 ECMA-402 API를 include하지 않으면 이 method의 following specification이 사용됩니다:

이 method는 this value(String string으로 converted됨)를 that(String thatValue로 converted됨)과 implementation-defined locale-sensitive String comparison한 result를 representing하는 NaN이 아닌 Number를 반환합니다. result는 host environment의 current locale의 conventions에 따른 String values의 sort order와 corresponding하도록 intended되며, stringthatValue보다 before로 ordered되면 negative, stringthatValue보다 after로 ordered되면 positive, 그리고 all other cases에서는 zero(stringthatValue 사이에 relative ordering이 없음을 representing)입니다.

comparisons를 수행하기 before, 이 method는 Strings를 prepare하기 위해 following steps를 수행합니다:

  1. thisValuethis value로 둔다.
  2. RequireObjectCoercible(thisValue)를 수행한다.
  3. string을 ? ToString(thisValue)로 둔다.
  4. thatValue를 ? ToString(that)로 둔다.

이 method에 대한 optional second 및 third parameters의 meaning은 ECMA-402 specification에 defined되어 있습니다; ECMA-402 support를 include하지 않는 implementations는 those parameter positions에 any other interpretation을 assign해서는 안 됩니다.

actual return values는 additional information을 encode할 수 있도록 implementation-defined이지만, 이 method는 two arguments의 method로 considered될 때 all Strings의 set에 total ordering을 defining하는 consistent comparator일 것이 required됩니다. 또한 이 method는 Unicode Standard에 따른 canonical equivalence를 recognize하고 honour해야 하며, distinguishable Strings가 canonically equivalent인 경우 comparing할 때 +0𝔽를 return하는 것도 include합니다.

Note 1

이 method 자체는 Array.prototype.sort의 argument로 직접 suitable하지 않습니다. latter는 two arguments의 function을 require하기 때문입니다.

Note 2

이 method는 ECMAScript environment가 host environment로부터 사용할 수 있는 whatever language- and/or locale-sensitive comparison functionality에 rely할 수 있으며, host environment의 current locale의 conventions에 따라 compare하도록 intended됩니다. However, comparison capabilities와 관계없이, 이 method는 Unicode Standard에 따른 canonical equivalence를 recognize하고 honour해야 합니다—예를 들어, following 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 FormsUnicode Technical Note #5, Canonical Equivalence in Applications를 참조하십시오. 또한 Unicode Technical Standard #10, Unicode Collation Algorithm도 참조하십시오.

이 method는 Unicode Standard chapter 3, section 3.7에 defined된 Unicode compatibility equivalents 또는 compatibility decompositions를 honour하지 않는 것이 recommended됩니다.

Note 3

이 method는 intentionally generic입니다; this value가 String object일 것을 require하지 않습니다. 따라서 method로 사용하기 위해 other kinds of objects에 transferred될 수 있습니다.

22.1.3.13 String.prototype.match ( regexpOrPattern )

이 method는 called될 때 following 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는 intentionally generic입니다; this value가 String object일 것을 require하지 않습니다. 따라서 method로 사용하기 위해 other kinds of objects에 transferred될 수 있습니다.

22.1.3.14 String.prototype.matchAll ( regexpOrPattern )

이 method는 this value를 representing하는 String에 대해 regexpOrPattern과 regular expression match를 수행하고 match results를 yield하는 iterator를 반환합니다. 각 match result는 String의 matched portion을 first element로 contain하고, 그 뒤에 any capturing groups에 의해 matched된 portions가 followed되는 Array입니다. regular expression이 never matches하면, returned iterator는 any match results도 yield하지 않습니다.

called될 때 following 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"를 contain하지 않으면, TypeError exception을 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는 intentionally generic입니다. this value가 String object일 것을 require하지 않습니다. 따라서 method로 사용하기 위해 other kinds of objects에 transferred될 수 있습니다.
Note 2
String.prototype.split과 similarly, String.prototype.matchAll은 typically 그 inputs를 mutating하지 않고 act하도록 designed되었습니다.

22.1.3.15 String.prototype.normalize ( [ form ] )

이 method는 called될 때 following 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 exception을 throw한다.
  7. normalthe latest Unicode Standard, Normalization Forms에 specified된 대로 form에 의해 named된 normalization form으로 string을 normalizing한 result인 String value로 둔다.
  8. normal을 반환한다.
Note

이 method는 intentionally generic입니다; this value가 String object일 것을 require하지 않습니다. 따라서 method로 사용하기 위해 other kinds of objects에 transferred될 수 있습니다.

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

이 method는 called될 때 following steps를 수행합니다:

  1. thisValuethis value로 둔다.
  2. RequireObjectCoercible(thisValue)를 수행한다.
  3. StringPaddingBuiltinsImpl(thisValue, maxLength, fillString, end)를 반환한다.

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

이 method는 called될 때 following 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. truncatedStringFillerfillString의 repeated concatenations로 구성되고 length fillLength로 truncated된 String value로 둔다.
  6. placementstart이면, truncatedStringFillerstringstring-concatenation을 반환한다.
  7. stringtruncatedStringFillerstring-concatenation을 반환한다.
Note 1

argument maxLengthstring의 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는 called될 때 following steps를 수행합니다:

  1. thisValuethis value로 둔다.
  2. RequireObjectCoercible(thisValue)를 수행한다.
  3. string을 ? ToString(thisValue)로 둔다.
  4. n을 ? ToIntegerOrInfinity(count)로 둔다.
  5. n < 0 또는 n = +∞이면, RangeError exception을 throw한다.
  6. n = 0이면, empty String을 반환한다.
  7. stringn copies가 appended together되어 만들어진 String value를 반환한다.
Note 1

이 method는 this value(String으로 converted됨)의 code units가 count times repeated된 String value를 create합니다.

Note 2

이 method는 intentionally generic입니다; this value가 String object일 것을 require하지 않습니다. 따라서 method로 사용하기 위해 other kinds of objects에 transferred될 수 있습니다.

22.1.3.19 String.prototype.replace ( searchValue, replaceValue )

이 method는 called될 때 following 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를 새 empty List로 둔다.
    3. replacement를 ! GetSubstitution(searchString, string, position, captures, undefined, replaceValue)로 둔다.
  15. preceding, replacement, 및 followingstring-concatenation을 반환한다.
Note

이 method는 intentionally generic입니다; this value가 String object일 것을 require하지 않습니다. 따라서 method로 사용하기 위해 other kinds of objects에 transferred될 수 있습니다.

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. Repeat, while templateRemainder is not the empty String,
    1. NOTE: following steps는 ref(templateRemainder의 prefix)를 isolate하고, refReplacement(그 replacement)를 determine한 뒤, 그 replacement를 result에 append한다.
    2. templateRemainder"$$"로 starts하면, 다음을 수행한다.
      1. ref"$$"로 둔다.
      2. refReplacement"$"로 둔다.
    3. 그렇지 않고 templateRemainder"$`"로 starts하면, 다음을 수행한다.
      1. ref"$`"로 둔다.
      2. refReplacementstring의 0부터 position까지의 substring으로 둔다.
    4. 그렇지 않고 templateRemainder"$&"로 starts하면, 다음을 수행한다.
      1. ref"$&"로 둔다.
      2. refReplacementmatched로 둔다.
    5. 그렇지 않고 templateRemainder"$'" (0x0024 (DOLLAR SIGN) followed by 0x0027 (APOSTROPHE))로 starts하면, 다음을 수행한다.
      1. ref"$'"로 둔다.
      2. matchLengthmatched의 length로 둔다.
      3. tailPositionposition + matchLength로 둔다.
      4. refReplacementstringmin(tailPosition, stringLength)부터의 substring으로 둔다.
      5. NOTE: tailPosition은 this abstract operation이 %RegExp.prototype%의 intrinsic %Symbol.replace% method를, "exec" property가 intrinsic %RegExp.prototype.exec%가 아닌 object에서 call하여 invoked된 경우에만 stringLength를 exceed할 수 있다.
    6. 그렇지 않고 templateRemainder"$" followed by 1 or more decimal digits로 starts하면, 다음을 수행한다.
      1. templateRemainder"$" followed by 2 or more decimal digits로 starts하면 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를 exceeding하는 index를 specify하면, one-digit replacement pattern followed by a literal digit로 treated된다.
        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"$<"로 starts하면, 다음을 수행한다.
      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는 called될 때 following 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"를 contain하지 않으면, TypeError exception을 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를 새 empty List로 둔다.
  11. positionStringIndexOf(string, searchString, 0)으로 둔다.
  12. Repeat, while position is not not-found,
    1. positionmatchPositions에 append한다.
    2. positionStringIndexOf(string, searchString, position + advanceBy)로 설정한다.
  13. endOfLastMatch를 0으로 둔다.
  14. result를 empty String으로 둔다.
  15. matchPositions의 각 element matchPosition에 대해, 다음을 수행한다.
    1. preservedstringendOfLastMatch부터 matchPosition까지의 substring으로 둔다.
    2. functionalReplacetrue이면, 다음을 수행한다.
      1. replacement를 ? ToString(? Call(replaceValue, undefined, « searchString, 𝔽(matchPosition), string »))로 둔다.
    3. 그렇지 않으면,
      1. Assert: replaceValue는 String이다.
      2. captures를 새 empty List로 둔다.
      3. replacement를 ! GetSubstitution(searchString, string, matchPosition, captures, undefined, replaceValue)로 둔다.
    4. resultresult, preserved, 및 replacementstring-concatenation으로 설정한다.
    5. endOfLastMatchmatchPosition + searchLength로 설정한다.
  16. endOfLastMatch < string의 length이면, 다음을 수행한다.
    1. resultresultstringendOfLastMatch부터의 substringstring-concatenation으로 설정한다.
  17. result를 반환한다.

22.1.3.21 String.prototype.search ( regexpOrPattern )

이 method는 called될 때 following 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는 intentionally generic입니다; this value가 String object일 것을 require하지 않습니다. 따라서 method로 사용하기 위해 other kinds of objects에 transferred될 수 있습니다.

22.1.3.22 String.prototype.slice ( start, end )

이 method는 this object를 String으로 converting한 result의 substring을 반환하며, index start에서 start하여 index end 전까지(or endundefined이면 String의 end까지) running합니다. start가 negative이면, 이는 sourceLength + start로 treated되며 여기서 sourceLength는 String의 length입니다. end가 negative이면, 이는 sourceLength + end로 treated되며 여기서 sourceLength는 String의 length입니다. result는 String value이며, String object가 아닙니다.

called될 때 following 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는 intentionally generic입니다; this value가 String object일 것을 require하지 않습니다. 따라서 method로 사용하기 위해 other kinds of objects에 transferred될 수 있습니다.

22.1.3.23 String.prototype.split ( separator, limit )

이 method는 this object를 String으로 converting한 result의 substrings가 stored된 Array를 반환합니다. substrings는 separator의 occurrences를 left to right로 searching하여 determined됩니다; 이러한 occurrences는 returned array 안의 any String의 part가 아니지만, String value를 divide up하는 역할을 합니다. separator의 value는 any length의 String일 수 있고, %Symbol.split% method를 가진 object(예: RegExp)일 수도 있습니다.

called될 때 following 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. codeUnitshead의 elements인 code units의 sequence로 구성된 List로 둔다.
    5. CreateArrayFromList(codeUnits)를 반환한다.
  11. string이 empty String이면, CreateArrayFromListstring »)를 반환한다.
  12. substrings를 새 empty List로 둔다.
  13. searchStart를 0으로 둔다.
  14. matchIndexStringIndexOf(string, separatorString, 0)으로 둔다.
  15. Repeat, while matchIndex is not not-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와 equal하고, 각 substring은 one code unit을 contain합니다.

this value가 empty String이거나 empty String으로 converts되면, result는 separator가 empty String과 match할 수 있는지 여부에 depends합니다. match할 수 있으면, result array는 no elements를 contain합니다. Otherwise, result array는 one element를 contain하며, 이는 empty String입니다.

separatorundefined이면, result array는 just one String을 contain하며, 이는 this value(String으로 converted됨)입니다. limitundefined가 아니면, output array는 no more than limit elements를 contain하도록 truncated됩니다.

Note 2

이 method는 intentionally generic입니다; this value가 String object일 것을 require하지 않습니다. 따라서 method로 사용하기 위해 other kinds of objects에 transferred될 수 있습니다.

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

이 method는 called될 때 following steps를 수행합니다:

  1. thisValuethis value로 둔다.
  2. RequireObjectCoercible(thisValue)를 수행한다.
  3. string을 ? ToString(thisValue)로 둔다.
  4. isRegexp를 ? IsRegExp(searchString)로 둔다.
  5. isRegexptrue이면, TypeError exception을 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하는 것은, future editions가 such argument values를 allow하는 extensions를 define할 수 있도록 specified되었습니다.

Note 2

이 method는 intentionally generic입니다; this value가 String object일 것을 require하지 않습니다. 따라서 method로 사용하기 위해 other kinds of objects에 transferred될 수 있습니다.

22.1.3.25 String.prototype.substring ( start, end )

이 method는 this object를 String으로 converting한 result의 substring을 반환하며, String의 index start에서 start하여 index end 전까지(or endundefined이면 String의 end까지) running합니다. result는 String value이며, String object가 아닙니다.

either argument가 NaN이거나 negative이면, zero로 replaced됩니다; either argument가 String의 length보다 strictly greater이면, String의 length로 replaced됩니다.

startend보다 strictly greater이면, 둘은 swapped됩니다.

called될 때 following 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는 intentionally generic입니다; this value가 String object일 것을 require하지 않습니다. 따라서 method로 사용하기 위해 other kinds of objects에 transferred될 수 있습니다.

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

ECMA-402 Internationalization API를 include하는 ECMAScript implementation은 ECMA-402 specification에 specified된 대로 이 method를 implement해야 합니다. ECMAScript implementation이 ECMA-402 API를 include하지 않으면 이 method의 following specification이 사용됩니다:

이 method는 6.1.4에 described된 대로 String value를 UTF-16 encoded code points의 sequence로 interpret합니다.

toLowerCase와 exactly same하게 works하지만, host environment의 current locale의 conventions와 corresponding하는 locale-sensitive result를 yield하도록 intended된다는 점이 다릅니다. regular Unicode case mappings와 해당 language의 rules가 conflict하는 few cases(예: Turkish)에서만 difference가 있을 것입니다.

이 method에 대한 optional parameters의 meaning은 ECMA-402 specification에 defined되어 있습니다; ECMA-402 support를 include하지 않는 implementations는 those parameter positions를 anything else에 사용해서는 안 됩니다.

Note

이 method는 intentionally generic입니다; this value가 String object일 것을 require하지 않습니다. 따라서 method로 사용하기 위해 other kinds of objects에 transferred될 수 있습니다.

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

ECMA-402 Internationalization API를 include하는 ECMAScript implementation은 ECMA-402 specification에 specified된 대로 이 method를 implement해야 합니다. ECMAScript implementation이 ECMA-402 API를 include하지 않으면 이 method의 following specification이 사용됩니다:

이 method는 6.1.4에 described된 대로 String value를 UTF-16 encoded code points의 sequence로 interpret합니다.

toUpperCase와 exactly same하게 works하지만, host environment의 current locale의 conventions와 corresponding하는 locale-sensitive result를 yield하도록 intended된다는 점이 다릅니다. regular Unicode case mappings와 해당 language의 rules가 conflict하는 few cases(예: Turkish)에서만 difference가 있을 것입니다.

이 method에 대한 optional parameters의 meaning은 ECMA-402 specification에 defined되어 있습니다; ECMA-402 support를 include하지 않는 implementations는 those parameter positions를 anything else에 사용해서는 안 됩니다.

Note

이 method는 intentionally generic입니다; this value가 String object일 것을 require하지 않습니다. 따라서 method로 사용하기 위해 other kinds of objects에 transferred될 수 있습니다.

22.1.3.28 String.prototype.toLowerCase ( )

이 method는 6.1.4에 described된 대로 String value를 UTF-16 encoded code points의 sequence로 interpret합니다.

called될 때 following 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뿐만 아니라 accompanying file SpecialCasing.txt 안의 모든 locale-insensitive mappings도 explicitly include합니다).

Note 1

some code points의 case mapping은 multiple code points를 produce할 수 있습니다. 이 경우 result String은 source String과 same length가 아닐 수 있습니다. toUpperCasetoLowerCase 모두 context-sensitive behaviour를 가지므로, methods는 symmetrical하지 않습니다. In other words, s.toUpperCase().toLowerCase()는 necessarily s.toLowerCase()와 equal하지 않습니다.

Note 2

이 method는 intentionally generic입니다; this value가 String object일 것을 require하지 않습니다. 따라서 method로 사용하기 위해 other kinds of objects에 transferred될 수 있습니다.

22.1.3.29 String.prototype.toString ( )

이 method는 called될 때 following steps를 수행합니다:

  1. ThisStringValue(this value)를 반환한다.
Note

String object의 경우, 이 method는 valueOf method와 same thing을 return합니다.

22.1.3.30 String.prototype.toUpperCase ( )

이 method는 6.1.4에 described된 대로 String value를 UTF-16 encoded code points의 sequence로 interpret합니다.

String.prototype.toLowerCase와 exactly same way로 behave하지만, String이 Unicode Default Case Conversion의 toUppercase algorithm을 사용하여 mapped된다는 점이 다릅니다.

Note

이 method는 intentionally generic입니다; this value가 String object일 것을 require하지 않습니다. 따라서 method로 사용하기 위해 other kinds of objects에 transferred될 수 있습니다.

22.1.3.31 String.prototype.toWellFormed ( )

이 method는 surrogate pair의 part가 아닌 모든 leading surrogatestrailing surrogates가 U+FFFD (REPLACEMENT CHARACTER)로 replaced된 이 object의 String representation을 반환합니다.

called될 때 following steps를 수행합니다:

  1. thisValuethis value로 둔다.
  2. RequireObjectCoercible(thisValue)를 수행한다.
  3. string을 ? ToString(thisValue)로 둔다.
  4. stringLengthstring의 length로 둔다.
  5. k를 0으로 둔다.
  6. result를 empty String으로 둔다.
  7. Repeat, while 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합니다.

called될 때 following steps를 수행합니다:

  1. thisValuethis value로 둔다.
  2. TrimString(thisValue, start+end)를 반환한다.
Note

이 method는 intentionally generic입니다; this value가 String object일 것을 require하지 않습니다. 따라서 method로 사용하기 위해 other kinds of objects에 transferred될 수 있습니다.

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을 leading white space가 removed된 string의 copy인 String value로 둔다.
  4. 그렇지 않고 whereend이면, 다음을 수행한다.
    1. trimmedString을 trailing white space가 removed된 string의 copy인 String value로 둔다.
  5. 그렇지 않으면,
    1. Assert: wherestart+end이다.
    2. trimmedString을 leading 및 trailing white space가 모두 removed된 string의 copy인 String value로 둔다.
  6. trimmedString을 반환한다.

white space의 definition은 WhiteSpaceLineTerminator의 union입니다. Unicode code point가 Unicode general category “Space_Separator” (“Zs”) 안에 있는지 determining할 때, code unit sequences는 6.1.4에 specified된 대로 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합니다.

called될 때 following steps를 수행합니다:

  1. stringthis value로 둔다.
  2. TrimString(string, end)를 반환한다.
Note

이 method는 intentionally generic입니다; this value가 String object일 것을 require하지 않습니다. 따라서 method로 사용하기 위해 other kinds of objects에 transferred될 수 있습니다.

22.1.3.34 String.prototype.trimStart ( )

이 method는 6.1.4에 described된 대로 String value를 UTF-16 encoded code points의 sequence로 interpret합니다.

called될 때 following steps를 수행합니다:

  1. stringthis value로 둔다.
  2. TrimString(string, start)를 반환한다.
Note

이 method는 intentionally generic입니다; this value가 String object일 것을 require하지 않습니다. 따라서 method로 사용하기 위해 other kinds of objects에 transferred될 수 있습니다.

22.1.3.35 String.prototype.valueOf ( )

이 method는 called될 때 following 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 exception을 throw한다.

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

이 method는 String value의 code points를 iterate하고, 각 code point를 String value로 반환하는 iterator object를 반환합니다.

called될 때 following steps를 수행합니다:

  1. stringthis value로 둔다.
  2. RequireObjectCoercible(string)를 수행한다.
  3. string을 ? ToString(string)으로 설정한다.
  4. string을 capture하고 called될 때 following steps를 수행하는, parameters가 없는 새 Abstract Closure closure를 둔다:
    1. lengthstring의 length로 둔다.
    2. position을 0으로 둔다.
    3. Repeat, while 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이며 such objects에 대해 specified된 internal methods를 가집니다. String instances는 String prototype object에서 properties를 inherit합니다. String instances는 또한 [[StringData]] internal slot을 가집니다. [[StringData]] internal slot은 이 String object가 represented하는 String value입니다.

String instances는 "length" property와 integer-indexed names를 가진 enumerable properties의 set을 가집니다.

22.1.4.1 length

이 String object가 represented하는 String value 안의 elements 수입니다.

String object가 initialized되면, 이 property는 unchanging입니다. 이는 attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }를 가집니다.

22.1.5 String Iterator Objects

String Iterator는 some specific String instance object에 대한 specific iteration을 represent하는 object입니다. String Iterator objects를 위한 named constructor는 없습니다. 대신, String Iterator objects는 String instance objects의 certain methods를 calling하여 created됩니다.

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를 contain합니다.

Note

regular expressions의 form과 functionality는 Perl 5 programming language의 regular expression facility를 model로 합니다.

22.2.1 Patterns

RegExp constructor는 input pattern String에 following grammar를 apply합니다. 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는 otherwise corresponding \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

여기서 first two lines는 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의 number of productions는 B.1.2 section에서 alternative definitions로 given됩니다.

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이 match한 source text가 Table 65의 “Property name and aliases” column에 listed된 Unicode property name 또는 property alias가 아니면 Syntax Error입니다.
  • UnicodePropertyValue가 match한 source text가 UnicodePropertyName이 match한 source text가 given하는 Unicode property 또는 property alias에 대한 property value 또는 property value alias로 PropertyValueAliases.txt에 listed되어 있지 않으면 Syntax Error입니다.
UnicodePropertyValueExpression :: LoneUnicodePropertyNameOrValue
  • LoneUnicodePropertyNameOrValue가 match한 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가 match한 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되는 any ( 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의 left에 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를 containing하는 Pattern으로 둔다.
  3. pattern 안에 contained된 Atom :: ( GroupSpecifieropt Disjunction ) Parse NodesparseNode before에 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: xy는 same enclosing Pattern을 가진다.
  2. enclosing Pattern Disjunction :: Alternative | Disjunction Parse Node를 contain하고, xAlternative 안에 contained되고 y가 derived Disjunction 안에 contained되거나, x가 derived Disjunction 안에 contained되고 yAlternative 안에 contained되면, 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)를 반환한다.

NonZeroDigit의 MV” 및 “DecimalDigits의 MV”의 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로 dividing한 remainder를 반환한다.
CharacterEscape :: 0 [lookahead ∉ DecimalDigit]
  1. U+0000 (NULL)의 numeric value를 반환한다.
Note 2

\0은 <NUL> character를 represent하며 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가 match한 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을 containing하는 Pattern으로 둔다.
  3. result를 새 empty List로 둔다.
  4. pattern이 contain하는 각 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. codePoints를 파생된 RegExpIdentifierNameRegExpIdentifierCodePoints라고 하자.
  2. codePointRegExpIdentifierPartRegExpIdentifierCodePoint라고 하자.
  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인 한, below에 listed된 것보다 more efficient algorithms를 use할 것이 encouraged됩니다. Abstract Closure는 RegExp object의 [[RegExpMatcher]] internal slot의 value로 사용됩니다.

Pattern은 its associated flags가 uv도 contain하지 않으면 BMP pattern입니다. Otherwise, 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를 describing하는 context에서 “character”는 single 16-bit Unicode BMP code point를 의미합니다. Unicode pattern의 behaviour를 describing하는 context에서 “character”는 UTF-16 encoded code point(6.1.4)를 의미합니다. 어느 context에서든, “character value”는 corresponding non-encoded code point의 numeric value를 의미합니다.

Pattern의 syntax 및 semantics는 Pattern의 source text가 SourceCharacter values의 List였던 것처럼 defined되며, 각 SourceCharacter는 Unicode code point에 corresponding합니다. BMP pattern이 non-BMP SourceCharacter를 contain하면 전체 pattern은 UTF-16을 사용하여 encoded되고, 그 encoding의 individual code units가 List의 elements로 사용됩니다.

Note

예를 들어, source text에서 single non-BMP character U+1D11E (MUSICAL SYMBOL G CLEF)로 expressed된 pattern을 consider하십시오. Unicode pattern으로 interpreted되면, 이는 single code point U+1D11E로 구성된 single element(character) List가 됩니다. However, BMP pattern으로 interpreted되면, 먼저 UTF-16 encoded되어 code units 0xD834 및 0xDD1E로 구성된 two element List를 produce합니다.

Patterns는 ECMAScript String values로 RegExp constructor에 passed되며, 그 안에서 non-BMP characters는 UTF-16 encoded됩니다. 예를 들어, String value로 expressed된 single character MUSICAL SYMBOL G CLEF pattern은 elements가 code units 0xD834 및 0xDD1E인 length 2의 String입니다. 따라서 이를 two pattern characters로 구성된 BMP pattern으로 process하기 위해서는 string의 further translation이 필요하지 않습니다. However, Unicode pattern으로 process하기 위해서는 sole element가 single pattern character, 즉 code point U+1D11E인 List를 producing하는 데 UTF16SurrogatePairToCodePoint를 사용해야 합니다.

implementation은 such translations를 실제로 UTF-16으로 또는 UTF-16으로부터 perform하지 않을 수 있지만, 이 specification의 semantics는 pattern matching의 result가 such translations가 performed된 것과 같아야 함을 require합니다.

22.2.2.1 Notation

아래 descriptions는 다음 internal data structures를 사용합니다:

  • CharSetElement는 following two entities 중 하나입니다:
    • regexpRecord.[[UnicodeSets]]false이면, CharSetElement는 위 Pattern Semantics의 sense에서 character입니다.
    • regexpRecord.[[UnicodeSets]]true이면, CharSetElement는 elements가 위 Pattern Semantics의 sense에서 characters인 sequence입니다. 이는 empty sequence, one character의 sequences, 및 more than one character의 sequences를 include합니다. convenience를 위해, 이러한 kind의 CharSetElements로 작업할 때 individual character는 one character의 sequence와 interchangeably treated됩니다.
  • CharSet은 CharSetElements의 mathematical set입니다.
  • CaptureRange는 capture에 included된 characters의 range를 represent하는 Record { [[StartIndex]], [[EndIndex]] }이며, 여기서 [[StartIndex]]input 안의 range의 start index(inclusive)를 representing하는 integer이고, [[EndIndex]]input 안의 range의 end index(exclusive)를 representing하는 integer입니다. any CaptureRange에 대해, these indices는 [[StartIndex]][[EndIndex]]라는 invariant를 satisfy해야 합니다.
  • MatchStateRecord { [[Input]], [[EndIndex]], [[Captures]] }이며, 여기서 [[Input]]은 matched되는 String을 representing하는 characters의 List이고, [[EndIndex]]integer이며, [[Captures]]는 pattern 안의 각 left-capturing parenthesis에 대해 하나씩 values의 List입니다. MatchStates는 regular expression matching algorithms에서 partial match states를 represent하는 데 사용됩니다. [[EndIndex]]는 지금까지 pattern에 의해 matched된 last input character의 index plus one이며, [[Captures]]는 capturing parentheses의 results를 hold합니다. [[Captures]]nth element는 nth set of capturing parentheses에 의해 captured된 characters의 range를 representing하는 CaptureRange이거나, nth set of capturing parentheses가 아직 reached되지 않은 경우 undefined입니다. backtracking 때문에, matching process 동안 many MatchStates가 언제든 use 중일 수 있습니다.
  • MatcherContinuation은 one MatchState argument를 take하고 MatchState 또는 failure를 return하는 Abstract Closure입니다. MatcherContinuation은 its MatchState argument가 given하는 intermediate state에서 starting하여 pattern의 remaining portion(closure의 captured values로 specified됨)을 input에 대해 match하려고 attempts합니다. match가 succeeds하면, MatcherContinuation은 reached한 final MatchState를 return합니다; match가 fails하면, MatcherContinuationfailure를 return합니다.
  • Matcher는 two arguments — MatchStateMatcherContinuation — 를 take하고 MatchState 또는 failure를 return하는 Abstract Closure입니다. Matcher는 pattern의 middle subpattern(closure의 captured values로 specified됨)을 MatchState[[Input]]에 대해, its MatchState argument가 given하는 intermediate state에서 starting하여 match하려고 attempts합니다. MatcherContinuation argument는 pattern의 rest를 match하는 closure이어야 합니다. pattern의 subpattern을 match하여 new MatchState를 obtain한 뒤, Matcher는 then that new MatchState에 대해 MatcherContinuation을 calls하여 pattern의 rest도 match할 수 있는지 test합니다. 가능하면, MatcherMatcherContinuation이 returned한 MatchState를 return합니다; 그렇지 않으면, Matcher는 its choice points에서 different choices를 try할 수 있으며, success하거나 all possibilities가 exhausted될 때까지 MatcherContinuation을 repeatedly calling합니다.

22.2.2.1.1 RegExp Records

RegExp Record는 compilation 중 및 possibly matching 중에 needed되는 RegExp에 대한 information을 store하는 데 사용되는 Record value입니다.

다음 fields를 가집니다:

Table 64: RegExp Record Fields
Field Name Value Meaning
[[IgnoreCase]] a Boolean "i"가 RegExp의 flags 안에 appear하는지 여부를 indicate합니다
[[Multiline]] a Boolean "m"가 RegExp의 flags 안에 appear하는지 여부를 indicate합니다
[[DotAll]] a Boolean "s"가 RegExp의 flags 안에 appear하는지 여부를 indicate합니다
[[Unicode]] a Boolean "u"가 RegExp의 flags 안에 appear하는지 여부를 indicate합니다
[[UnicodeSets]] a Boolean "v"가 RegExp의 flags 안에 appear하는지 여부를 indicate합니다
[[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 regexpRecordforward와 함께 DisjunctionCompileSubpattern으로 둔다.
  2. regexpRecordm을 capture하고 called될 때 following steps를 수행하는, parameters (input, index)를 가진 새 Abstract Closure를 반환한다:
    1. Assert: input은 characters의 List이다.
    2. Assert: 0 ≤ indexinput 안의 elements 수이다.
    3. 아무것도 capture하지 않고 called될 때 following steps를 수행하는, parameters (y)를 가진 새 MatcherContinuation c를 둔다:
      1. Assert: yMatchState이다.
      2. y를 반환한다.
    4. capabilityregexpRecord.[[CapturingGroupsCount]]개의 undefined values의 List로 두며, 1부터 regexpRecord.[[CapturingGroupsCount]]까지 indexed된다.
    5. xMatchState { [[Input]]: input, [[EndIndex]]: index, [[Captures]]: capability }로 둔다.
    6. m(x, c)를 반환한다.
Note

Pattern은 Abstract Closure value로 compiles됩니다. RegExpBuiltinExec는 then 이 procedure를 characters의 List와 그 List 안의 offset에 apply하여 pattern이 그 List 안의 exactly that offset에서 starting하여 match할지, 그리고 match한다면 capturing parentheses의 values가 무엇인지 determine할 수 있습니다. 22.2.2의 algorithms는 pattern을 compiling하는 것이 SyntaxError exception을 throw할 수 있도록 designed되어 있습니다; 반면 pattern이 successfully compiled된 후, resulting Abstract Closure를 apply하여 characters의 List에서 match를 find하는 것은 exception을 throw할 수 없습니다(out-of-memory처럼 anywhere에서 occur할 수 있는 any 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 regexpRecorddirection과 함께 AlternativeCompileSubpattern으로 둔다.
  2. m2를 arguments regexpRecorddirection과 함께 DisjunctionCompileSubpattern으로 둔다.
  3. MatchTwoAlternatives(m1, m2)를 반환한다.
Note 2

| regular expression operator는 two alternatives를 separates합니다. pattern은 first left Alternative를 match하려고 tries합니다(regular expression의 sequel이 followed됨); if it fails, right Disjunction을 match하려고 tries합니다(regular expression의 sequel이 followed됨). left Alternative, right Disjunction, 그리고 sequel이 모두 choice points를 가지면, left Alternative의 next choice로 moving하기 전에 sequel 안의 all choices가 tried됩니다. left Alternative의 choices가 exhausted되면, left Alternative 대신 right Disjunction이 tried됩니다. |에 의해 skipped된 pattern portion 안의 any capturing parentheses는 Strings 대신 undefined values를 produce합니다. 따라서, 예를 들어,

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

"ab"가 아니라 result "a"를 반환합니다. Moreover,

/((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 regexpRecorddirection과 함께 AlternativeCompileSubpattern으로 둔다.
  2. m2를 arguments regexpRecorddirection과 함께 TermCompileSubpattern으로 둔다.
  3. MatchSequence(m1, m2, direction)을 반환한다.
Note 3

Consecutive Terms는 input의 consecutive portions를 simultaneously match하려고 try합니다. directionforward이면, left Alternative, right Term, 그리고 regular expression의 sequel이 모두 choice points를 가지는 경우, right Term의 next choice로 moving하기 전에 sequel 안의 all choices가 tried되고, left Alternative의 next choice로 moving하기 전에 right Term 안의 all choices가 tried됩니다. directionbackward이면, AlternativeTerm의 evaluation order가 reversed됩니다.

Term :: Assertion
  1. argument regexpRecord와 함께 AssertionCompileAssertion을 반환한다.
Note 4

resulting Matcherdirection과 independent합니다.

Term :: Atom
  1. arguments regexpRecorddirection과 함께 AtomCompileAtom을 반환한다.
Term :: Atom Quantifier
  1. m을 arguments regexpRecorddirection과 함께 AtomCompileAtom으로 둔다.
  2. qQuantifierCompileQuantifier로 둔다.
  3. Assert: q.[[Min]]q.[[Max]]이다.
  4. parenIndexCountLeftCapturingParensBefore(Term)로 둔다.
  5. parenCountCountLeftCapturingParensWithin(Atom)으로 둔다.
  6. m, q, parenIndex, 및 parenCount를 capture하고 called될 때 following steps를 수행하는, parameters (x, c)를 가진 새 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. m, min, max, greedy, matchState, continue, parenIndex, 및 parenCount를 capture하고 called될 때 following steps를 수행하는, parameters (y)를 가진 새 MatcherContinuation d를 둔다:
    1. Assert: yMatchState이다.
    2. min = 0이고 y.[[EndIndex]] = matchState.[[EndIndex]]이면, failure를 반환한다.
    3. min = 0이면 min2를 0으로 둔다; else min2min - 1로 둔다.
    4. max = +∞이면 max2를 +∞로 둔다; else 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

Atom 뒤에 Quantifier가 followed되면 Quantifier가 specified한 number of times만큼 repeated됩니다. Quantifier는 non-greedy일 수 있으며, 이 경우 Atom pattern은 sequel을 still matching하면서 possible한 few times만 repeated됩니다. 또는 greedy일 수 있으며, 이 경우 Atom pattern은 sequel을 still matching하면서 possible한 many times만 repeated됩니다. Atom pattern은 그것이 match하는 input character sequence가 아니라 pattern itself가 repeated되므로, Atom의 different repetitions는 different input substrings를 match할 수 있습니다.

Note 2

Atom과 regular expression의 sequel이 모두 choice points를 가지면, Atom은 first possible한 many times(or non-greedy이면 possible한 few times)만큼 matched됩니다. last repetition of Atom의 next choice로 moving하기 전에 sequel 안의 all choices가 tried됩니다. Atom의 last (nth) repetition 안의 all choices는 Atom의 next-to-last (n - 1)st repetition 안의 next choice로 moving하기 전에 tried됩니다; at which point Atom의 more or fewer repetitions가 now possible한 것으로 turn out될 수 있습니다; these are exhausted됩니다(again, 가능한 few 또는 many 것으로 starting) before moving on to the next choice in the (n - 1)st repetition of Atom and so on.

Compare

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

which returns "abcde" with

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

which returns "abc".

Consider also

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

which, by the choice point ordering above, returns the array

["aaba", "ba"]

and not any of:

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

위 choice points의 ordering은 two numbers(unary notation으로 represented됨)의 greatest common divisor를 calculate하는 regular expression을 writing하는 데 사용될 수 있습니다. following example은 10과 15의 gcd를 calculates합니다:

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

which returns the gcd in unary notation "aaaaa".

Note 3

RepeatMatcher의 step 4Atom이 repeated될 때마다 Atom의 captures를 clears합니다. 우리는 regular expression

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

에서 its behaviour를 볼 수 있으며, 이는 array

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

를 반환하고, 다음을 반환하지 않습니다

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

because outermost *의 each iteration은 quantified Atom 안에 contained된 all captured Strings를 clears하고, 이 case에서는 capture Strings numbered 2, 3, 4, 및 5를 include하기 때문입니다.

Note 4

RepeatMatcher의 step 2.b는 minimum number of repetitions가 satisfied되면, empty character sequence를 match하는 Atom의 any more expansions는 further repetitions에 considered되지 않는다고 states합니다. 이는 regular expression engine이 다음과 같은 patterns에서 infinite loop에 빠지는 것을 prevents합니다:

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

or the slightly more complicated:

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

which returns the 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. 아무것도 capture하지 않고 called될 때 following steps를 수행하는, parameters (matchState, continue)를 가진 새 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. m1m2를 capture하고 called될 때 following steps를 수행하는, parameters (matchState, continue)를 가진 새 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. m1m2를 capture하고 called될 때 following steps를 수행하는, parameters (matchState, continue)를 가진 새 Matcher를 반환한다:
      1. Assert: matchStateMatchState이다.
      2. Assert: continueMatcherContinuation이다.
      3. continuem2를 capture하고 called될 때 following steps를 수행하는, parameters (y)를 가진 새 MatcherContinuation d를 둔다:
        1. Assert: yMatchState이다.
        2. m2(y, continue)를 반환한다.
      4. m1(matchState, d)를 반환한다.
  2. Assert: directionbackward이다.
  3. m1m2를 capture하고 called될 때 following steps를 수행하는, parameters (matchState, continue)를 가진 새 Matcher를 반환한다:
    1. Assert: matchStateMatchState이다.
    2. Assert: continueMatcherContinuation이다.
    3. continuem1을 capture하고 called될 때 following steps를 수행하는, parameters (y)를 가진 새 MatcherContinuation d를 둔다:
      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될 때 following steps를 수행하는, parameters (matchState, continue)를 가진 새 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과 함께 used될 때조차, ^는 always input의 beginning에서만, 또는(regexpRecord.[[Multiline]]true이면) line의 beginning에서만 matches합니다.

Assertion :: $
  1. regexpRecord를 capture하고 called될 때 following steps를 수행하는, parameters (matchState, continue)를 가진 새 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될 때 following steps를 수행하는, parameters (matchState, continue)를 가진 새 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될 때 following steps를 수행하는, parameters (matchState, continue)를 가진 새 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 regexpRecordforward와 함께 DisjunctionCompileSubpattern으로 둔다.
  2. m을 capture하고 called될 때 following steps를 수행하는, parameters (matchState, continue)를 가진 새 Matcher를 반환한다:
    1. Assert: matchStateMatchState이다.
    2. Assert: continueMatcherContinuation이다.
    3. 아무것도 capture하지 않고 called될 때 following steps를 수행하는, parameters (y)를 가진 새 MatcherContinuation d를 둔다:
      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를 specifies합니다. 이것이 succeed하려면, Disjunction 안의 pattern이 current position에서 match해야 하지만, sequel을 matching하기 전에 current position은 advanced되지 않습니다. Disjunction이 current position에서 several ways로 match할 수 있으면, only first one이 tried됩니다. other regular expression operators와 달리, (?= form 안으로의 backtracking은 없습니다(this unusual behaviour는 Perl로부터 inherited되었습니다). 이는 Disjunction이 capturing parentheses를 contain하고 pattern의 sequel이 those captures에 대한 backreferences를 contain할 때만 matters합니다.

예를 들어,

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

는 first b 바로 뒤의 empty String을 matches하므로 array를 반환합니다:

["", "aaa"]

lookahead 안으로 backtracking이 없는 것을 illustrate하기 위해 다음을 consider하십시오:

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

이 expression은 다음을 반환합니다

["aba", "a"]

그리고 다음을 반환하지 않습니다:

["aaaba", "a"]
Assertion :: (?! Disjunction )
  1. m을 arguments regexpRecordforward와 함께 DisjunctionCompileSubpattern으로 둔다.
  2. m을 capture하고 called될 때 following steps를 수행하는, parameters (matchState, continue)를 가진 새 Matcher를 반환한다:
    1. Assert: matchStateMatchState이다.
    2. Assert: continueMatcherContinuation이다.
    3. 아무것도 capture하지 않고 called될 때 following steps를 수행하는, parameters (y)를 가진 새 MatcherContinuation d를 둔다:
      1. Assert: yMatchState이다.
      2. y를 반환한다.
    4. resultm(matchState, d)로 둔다.
    5. resultfailure가 아니면, failure를 반환한다.
    6. continue(matchState)를 반환한다.
Note 4

form (?! Disjunction )는 zero-width negative lookahead를 specifies합니다. 이것이 succeed하려면, Disjunction 안의 pattern이 current position에서 match하지 못해야 합니다. sequel을 matching하기 전에 current position은 advanced되지 않습니다. Disjunction은 capturing parentheses를 contain할 수 있지만, them에 대한 backreferences는 Disjunction itself 안에서만 sense를 가집니다. pattern의 elsewhere에서 these capturing parentheses에 대한 Backreferences는 negative lookahead가 pattern이 succeed하기 위해 fail해야 하므로 always undefined를 return합니다. 예를 들어,

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

는 positive number n of a's, b, another n a's(first \2로 specified됨), 그리고 c가 immediately followed하지 않는 a를 looks for합니다. second \2는 negative lookahead outside에 있으므로, undefined에 대해 matches하고 따라서 always succeeds합니다. whole expression은 array를 반환합니다:

["baaabaac", "ba", undefined, "abaac"]
Assertion :: (?<= Disjunction )
  1. m을 arguments regexpRecordbackward와 함께 DisjunctionCompileSubpattern으로 둔다.
  2. m을 capture하고 called될 때 following steps를 수행하는, parameters (matchState, continue)를 가진 새 Matcher를 반환한다:
    1. Assert: matchStateMatchState이다.
    2. Assert: continueMatcherContinuation이다.
    3. 아무것도 capture하지 않고 called될 때 following steps를 수행하는, parameters (y)를 가진 새 MatcherContinuation d를 둔다:
      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 regexpRecordbackward와 함께 DisjunctionCompileSubpattern으로 둔다.
  2. m을 capture하고 called될 때 following steps를 수행하는, parameters (matchState, continue)를 가진 새 Matcher를 반환한다:
    1. Assert: matchStateMatchState이다.
    2. Assert: continueMatcherContinuation이다.
    3. 아무것도 capture하지 않고 called될 때 following steps를 수행하는, parameters (y)를 가진 새 MatcherContinuation d를 둔다:
      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를 contain하면, 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를 contain하는 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에 corresponding하는 all characters를 charSet에서 remove한다.
  3. CharacterSetMatcher(regexpRecord, charSet, false, direction)를 반환한다.
Atom :: CharacterClass
  1. cc를 argument regexpRecord와 함께 CharacterClassCompileCharacterClass로 둔다.
  2. cscc.[[CharSet]]으로 둔다.
  3. regexpRecord.[[UnicodeSets]]false이거나 cs의 every CharSetElement가 single character로 구성되면(cs가 empty인 경우 포함), CharacterSetMatcher(regexpRecord, cs, cc.[[Invert]], direction)를 반환한다.
  4. Assert: cc.[[Invert]]false이다.
  5. listOfMatchers를 empty List of Matchers로 둔다.
  6. cs 안의 more than 1 character를 contain하는 각 CharSetElement s에 대해, length의 descending order로 iterating하며 다음을 수행한다.
    1. cs2s의 last code point를 contain하는 one-element CharSet으로 둔다.
    2. m2CharacterSetMatcher(regexpRecord, cs2, false, direction)로 둔다.
    3. s 안의 각 code point c1에 대해, its second-to-last code point부터 backwards로 iterating하며 다음을 수행한다.
      1. cs1c1을 contain하는 one-element CharSet으로 둔다.
      2. m1CharacterSetMatcher(regexpRecord, cs1, false, direction)로 둔다.
      3. m2MatchSequence(m1, m2, direction)으로 설정한다.
    4. m2listOfMatchers에 append한다.
  7. singles를 single character로 구성된 cs의 every CharSetElement를 contain하는 CharSet으로 둔다.
  8. CharacterSetMatcher(regexpRecord, singles, false, direction)를 listOfMatchers에 append한다.
  9. cs가 characters의 empty sequence를 contain하면, EmptyMatcher()를 listOfMatchers에 append한다.
  10. m2listOfMatchers 안의 last Matcher로 둔다.
  11. listOfMatchers의 각 Matcher m1에 대해, its second-to-last element부터 backwards로 iterating하며 다음을 수행한다.
    1. m2MatchTwoAlternatives(m1, m2)로 설정한다.
  12. m2를 반환한다.
Atom :: ( GroupSpecifieropt Disjunction )
  1. m을 arguments regexpRecorddirection과 함께 DisjunctionCompileSubpattern으로 둔다.
  2. parenIndexCountLeftCapturingParensBefore(Atom)로 둔다.
  3. direction, m, 및 parenIndex를 capture하고 called될 때 following steps를 수행하는, parameters (x, c)를 가진 새 Matcher를 반환한다:
    1. Assert: xMatchState이다.
    2. Assert: cMatcherContinuation이다.
    3. x, c, direction, 및 parenIndex를 capture하고 called될 때 following steps를 수행하는, parameters (y)를 가진 새 MatcherContinuation d를 둔다:
      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. Else,
        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를 together group하고 match result를 save하는 two roles를 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 modifiedRerdirection과 함께 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 modifiedRerdirection과 함께 DisjunctionCompileSubpattern을 반환한다.
AtomEscape :: DecimalEscape
  1. nDecimalEscapeCapturingGroupNumber로 둔다.
  2. Assert: nregexpRecord.[[CapturingGroupsCount]]이다.
  3. BackreferenceMatcher(regexpRecord, « n », direction)를 반환한다.
Note 3

form \ followed by a non-zero decimal number n의 escape sequence는 nth set of capturing parentheses의 result(22.2.2.1)를 matches합니다. regular expression이 n보다 fewer capturing parentheses를 가지면 error입니다. regular expression이 n 또는 more capturing parentheses를 가지지만 nth one이 아무것도 capture하지 않았기 때문에 undefined이면, backreference는 always succeeds합니다.

AtomEscape :: CharacterEscape
  1. charValueCharacterEscapeCharacterValue로 둔다.
  2. char를 character value가 charValue인 character로 둔다.
  3. charSet을 character char를 contain하는 one-element CharSet으로 둔다.
  4. CharacterSetMatcher(regexpRecord, charSet, false, direction)를 반환한다.
AtomEscape :: CharacterClassEscape
  1. cs를 argument regexpRecord와 함께 CharacterClassEscapeCompileToCharSet으로 둔다.
  2. regexpRecord.[[UnicodeSets]]false이거나 cs의 every CharSetElement가 single character로 구성되면(cs가 empty인 경우 포함), CharacterSetMatcher(regexpRecord, cs, false, direction)를 반환한다.
  3. listOfMatchers를 empty List of Matchers로 둔다.
  4. cs 안의 more than 1 character를 contain하는 각 CharSetElement s에 대해, length의 descending order로 iterating하며 다음을 수행한다.
    1. cs2s의 last code point를 contain하는 one-element CharSet으로 둔다.
    2. m2CharacterSetMatcher(regexpRecord, cs2, false, direction)로 둔다.
    3. s 안의 각 code point c1에 대해, its second-to-last code point부터 backwards로 iterating하며 다음을 수행한다.
      1. cs1c1을 contain하는 one-element CharSet으로 둔다.
      2. m1CharacterSetMatcher(regexpRecord, cs1, false, direction)로 둔다.
      3. m2MatchSequence(m1, m2, direction)으로 설정한다.
    4. m2listOfMatchers에 append한다.
  5. singles를 single character로 구성된 cs의 every CharSetElement를 contain하는 CharSet으로 둔다.
  6. CharacterSetMatcher(regexpRecord, singles, false, direction)를 listOfMatchers에 append한다.
  7. cs가 characters의 empty sequence를 contain하면, EmptyMatcher()를 listOfMatchers에 append한다.
  8. m2listOfMatchers 안의 last Matcher로 둔다.
  9. listOfMatchers의 각 Matcher m1에 대해, its second-to-last element부터 backwards로 iterating하며 다음을 수행한다.
    1. m2MatchTwoAlternatives(m1, m2)로 설정한다.
  10. m2를 반환한다.
AtomEscape :: k GroupName
  1. matchingGroupSpecifiersGroupSpecifiersThatMatch(GroupName)으로 둔다.
  2. parenIndices를 새 empty 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의 Every CharSetElement는 single character로 구성된다.
  2. regexpRecord, charSet, invert, 및 direction을 capture하고 called될 때 following steps를 수행하는, parameters (x, c)를 가진 새 Matcher를 반환한다:
    1. Assert: xMatchState이다.
    2. Assert: cMatcherContinuation이다.
    3. inputx.[[Input]]으로 둔다.
    4. endIndexx.[[EndIndex]]로 둔다.
    5. directionforward이면, fendIndex + 1로 둔다.
    6. Else, 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를 containing하는 CharSetElementcharSet 안에 존재하면 foundtrue로 둔다; else 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. regexpRecord, ns, 및 direction을 capture하고 called될 때 following steps를 수행하는, parameters (x, c)를 가진 새 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. Else, 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을 provide하면, 그 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에서, all characters는 compared되기 immediately before Unicode Standard가 provided하는 simple mapping을 사용하여 implicitly case-folded됩니다. simple mapping은 always single code point로 maps하므로, 예를 들어 ß (U+00DF LATIN SMALL LETTER SHARP S)를 ss 또는 SS로 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됩니다. those code points를 contain하는 Strings는 /[a-z]/ui와 같은 regular expressions에 의해 matched됩니다.

HasEitherUnicodeFlag(regexpRecord)가 false인 case-insignificant matches에서, mapping은 toCasefold가 아니라 Unicode Default Case Conversion algorithm toUppercase에 based하며, 이는 some subtle differences를 result합니다. 예를 들어, (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: addremove는 common elements를 가지지 않는다.
  2. ignoreCaseregexpRecord.[[IgnoreCase]]로 둔다.
  3. multilineregexpRecord.[[Multiline]]로 둔다.
  4. dotAllregexpRecord.[[DotAll]]로 둔다.
  5. unicoderegexpRecord.[[Unicode]]로 둔다.
  6. unicodeSetsregexpRecord.[[UnicodeSets]]로 둔다.
  7. capturingGroupsCountregexpRecord.[[CapturingGroupsCount]]로 둔다.
  8. remove"i"를 contain하면, ignoreCasefalse로 설정한다.
  9. Else if add"i"를 contain하면, ignoreCasetrue로 설정한다.
  10. remove"m"를 contain하면, multilinefalse로 설정한다.
  11. Else if add"m"를 contain하면, multilinetrue로 설정한다.
  12. remove"s"를 contain하면, dotAllfalse로 설정한다.
  13. Else if add"s"를 contain하면, 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 charSetotherSet의 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. rangeSetremainingSet의 union을 반환한다.
NonemptyClassRangesNoDash :: ClassAtomNoDash NonemptyClassRangesNoDash
  1. charSet을 argument regexpRecord와 함께 ClassAtomNoDashCompileToCharSet으로 둔다.
  2. otherSet을 argument regexpRecord와 함께 NonemptyClassRangesNoDashCompileToCharSet으로 둔다.
  3. CharSets charSetotherSet의 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. rangeSetremainingSet의 union을 반환한다.
Note 2

ClassContents는 single ClassAtom 및/또는 dashes로 separated된 two ClassAtom의 ranges로 expand될 수 있습니다. latter case에서 ClassContents는 first ClassAtom과 second ClassAtom 사이의 all characters를 inclusive로 include합니다; either ClassAtom이 single character를 represent하지 않으면(예: one이 \w인 경우) 또는 first ClassAtom의 character value가 second ClassAtom의 character value보다 strictly greater이면 error가 occurs합니다.

Note 3

pattern이 case를 ignores하더라도, range의 two ends의 case는 어떤 characters가 range에 belong하는지 determining하는 데 significant합니다. 따라서 예를 들어, pattern /[E-F]/i는 letters E, F, e, 및 f만 matches하는 반면, pattern /[E-f]/i는 Unicode Basic Latin block 안의 all uppercase and lowercase letters 및 symbols [, \, ], ^, _, 그리고 `를 matches합니다.

Note 4

- character는 literally treated될 수 있고 range를 denote할 수도 있습니다. It is treated literally if it is the first or last character of ClassContents, the beginning or end limit of a range specification, or immediately follows a range specification.

ClassAtom :: -
  1. single character - U+002D (HYPHEN-MINUS)를 contain하는 CharSet을 반환한다.
ClassAtomNoDash :: SourceCharacter but not one of \ or ] or -
  1. SourceCharacter가 matched한 character를 contain하는 CharSet을 반환한다.
ClassEscape :: b - CharacterEscape
  1. charValue를 this ClassEscapeCharacterValue로 둔다.
  2. char를 character value가 charValue인 character로 둔다.
  3. single character char를 contain하는 CharSet을 반환한다.
Note 5

ClassAtom은 regular expression의 rest에서 allowed되는 any escape sequences를 사용할 수 있지만, \b, \B, 및 backreferences는 제외합니다. CharacterClass 안에서 \b는 backspace character를 의미하는 반면, \B 및 backreferences는 errors를 raise합니다. ClassAtom 안에서 backreference를 사용하면 error가 causes됩니다.

CharacterClassEscape :: d
  1. characters 0, 1, 2, 3, 4, 5, 6, 7, 8, 및 9를 contain하는 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에 corresponding하는 all characters를 contain하는 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은 only single code points를 contain한다.
  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를 include하는 all Unicode code points를 contain하는 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. character database definition이 property “General_Category” with value s를 include하는 all Unicode code points를 contain하는 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”를 include하는 all CharSetElements를 contain하는 CharSet으로 둔다.
  6. MaybeSimpleCaseFolding(regexpRecord, charSet)를 반환한다.
ClassUnion :: ClassSetRange ClassUnionopt
  1. charSet을 argument regexpRecord와 함께 ClassSetRangeCompileToCharSet으로 둔다.
  2. ClassUnion이 present하면, 다음을 수행한다.
    1. otherSet을 argument regexpRecord와 함께 ClassUnionCompileToCharSet으로 둔다.
    2. CharSets charSetotherSet의 union을 반환한다.
  3. charSet을 반환한다.
ClassUnion :: ClassSetOperand ClassUnionopt
  1. charSet을 argument regexpRecord와 함께 ClassSetOperandCompileToCharSet으로 둔다.
  2. ClassUnion이 present하면, 다음을 수행한다.
    1. otherSet을 argument regexpRecord와 함께 ClassUnionCompileToCharSet으로 둔다.
    2. CharSets charSetotherSet의 union을 반환한다.
  3. charSet을 반환한다.
ClassIntersection :: ClassSetOperand && ClassSetOperand
  1. charSet을 argument regexpRecord와 함께 first ClassSetOperandCompileToCharSet으로 둔다.
  2. otherSet을 argument regexpRecord와 함께 second ClassSetOperandCompileToCharSet으로 둔다.
  3. CharSets charSetotherSet의 intersection을 반환한다.
ClassIntersection :: ClassIntersection && ClassSetOperand
  1. charSet을 argument regexpRecord와 함께 ClassIntersectionCompileToCharSet으로 둔다.
  2. otherSet을 argument regexpRecord와 함께 ClassSetOperandCompileToCharSet으로 둔다.
  3. CharSets charSetotherSet의 intersection을 반환한다.
ClassSubtraction :: ClassSetOperand -- ClassSetOperand
  1. charSet을 argument regexpRecord와 함께 first ClassSetOperandCompileToCharSet으로 둔다.
  2. otherSet을 argument regexpRecord와 함께 second ClassSetOperandCompileToCharSet으로 둔다.
  3. otherSet의 CharSetElements도 아닌 charSet의 CharSetElements를 contain하는 CharSet을 반환한다.
ClassSubtraction :: ClassSubtraction -- ClassSetOperand
  1. charSet을 argument regexpRecord와 함께 ClassSubtractionCompileToCharSet으로 둔다.
  2. otherSet을 argument regexpRecord와 함께 ClassSetOperandCompileToCharSet으로 둔다.
  3. otherSet의 CharSetElements도 아닌 charSet의 CharSetElements를 contain하는 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는 often two or more ranges로 구성됩니다. UnicodeSets가 true이고 IgnoreCase가 true이면, MaybeSimpleCaseFolding(regexpRecord, [Ā-č])는 그 range의 odd-numbered code points만 include합니다.

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를 contain하는 CharSet을 반환한다.
ClassStringDisjunctionContents :: ClassString | ClassStringDisjunctionContents
  1. s를 argument regexpRecord와 함께 ClassStringCompileClassSetString으로 둔다.
  2. charSet을 one string s를 contain하는 CharSet으로 둔다.
  3. otherSet을 argument regexpRecord와 함께 ClassStringDisjunctionContentsCompileToCharSet으로 둔다.
  4. CharSets charSetotherSet의 union을 반환한다.
ClassSetCharacter :: SourceCharacter but not ClassSetSyntaxCharacter \ CharacterEscape \ ClassSetReservedPunctuator
  1. charValue를 this ClassSetCharacterCharacterValue로 둔다.
  2. char를 character value가 charValue인 character로 둔다.
  3. single character char를 contain하는 CharSet을 반환한다.
ClassSetCharacter :: \b
  1. single character U+0008 (BACKSPACE)를 contain하는 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: charSetotherSet은 각각 exactly one character를 contain한다.
  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를 가진 all characters를 contain하는 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를 contain하는 CharSet을 반환합니다. It performs the following steps when called:

  1. basicWordCharsASCII word characters 안의 every character를 contain하는 CharSet으로 둔다.
  2. extraWordCharscbasicWordChars 안에 없지만 Canonicalize(regexpRecord, c)가 basicWordChars 안에 있는 all characters c를 contain하는 CharSet으로 둔다.
  3. Assert: HasEitherUnicodeFlag(regexpRecord)가 true이고 regexpRecord.[[IgnoreCase]]true인 경우가 아니면 extraWordChars는 empty이다.
  4. basicWordCharsextraWordChars의 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을 가지지 않는 all Unicode code points c를 contain하는 CharSet을 반환한다(즉, scf(c)=c).
  2. HasEitherUnicodeFlag(regexpRecord)가 true이면, 다음을 수행한다.
    1. all code point values를 contain하는 CharSet을 반환한다.
  3. all code unit values를 contain하는 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을 반환합니다. Otherwise, Unicode Character Database의 file CaseFolding.txt 안의 Simple Case Folding (scf(codePoint)) definitions(each maps a single code point to another single code point)를 사용하여 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을 새 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를 contain하는 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 65, Table 66, 및 Table 67에 listed된 Unicode property names 및 aliases를 support해야 합니다. interoperability를 ensure하기 위해, implementations는 any other property names 또는 aliases를 support해서는 안 됩니다.

Note 1

예를 들어, Script_Extensions(property name) 및 scx(property alias)는 valid이지만, script_extensions 또는 Scx는 그렇지 않습니다.

Note 2

listed properties는 UTS18 RL1.2가 require하는 것의 superset을 form합니다.

Note 3

these tables의 entries의 spellings(casing 포함)는 Unicode Character Database의 file PropertyAliases.txt에서 used되는 spellings와 match합니다. that 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는 any other property values 또는 property value aliases를 support해서는 안 됩니다.

Note 1

예를 들어, XpeoOld_Persian은 valid Script_Extensions values이지만, xpeoOld Persian은 그렇지 않습니다.

Note 2

이 algorithm은 UAX44에 listed된 symbolic values에 대한 matching rules와 다릅니다: case, white space, U+002D (HYPHEN-MINUS), 및 U+005F (LOW LINE)는 ignored되지 않고, Is prefix는 supported되지 않습니다.

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. s1cs의 single CharSetElement인 characters의 sequence로 둔다.
  3. NonEmptyClassString이 present하면, 다음을 수행한다.
    1. s2를 argument regexpRecord와 함께 NonEmptyClassStringCompileClassSetString으로 둔다.
    2. s1s2의 concatenation을 반환한다.
  4. s1을 반환한다.

22.2.3 RegExp 생성용 Abstract Operations

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. Else, pattern을 ? ToString(pattern)으로 설정한다.
  3. flagsundefined이면, flags를 empty String으로 설정한다.
  4. Else, flags를 ? ToString(flags)로 설정한다.
  5. flags"d", "g", "i", "m", "s", "u", "v", 또는 "y" 이외의 any code unit을 contain하면, SyntaxError exception을 throw한다.
  6. flags가 any code unit을 more than once contain하면, SyntaxError exception을 throw한다.
  7. flags"i"를 contain하면, itrue로 둔다; else ifalse로 둔다.
  8. flags"m"를 contain하면, mtrue로 둔다; else mfalse로 둔다.
  9. flags"s"를 contain하면, strue로 둔다; else sfalse로 둔다.
  10. flags"u"를 contain하면, utrue로 둔다; else ufalse로 둔다.
  11. flags"v"를 contain하면, vtrue로 둔다; else vfalse로 둔다.
  12. utrue이거나 vtrue이면, 다음을 수행한다.
    1. patternTextStringToCodePoints(pattern)로 둔다.
  13. Else,
    1. patternTextpattern의 각 16-bit element를 Unicode BMP code point로 interpreting한 result로 둔다. UTF-16 decoding은 elements에 applied되지 않는다.
  14. parseResultParsePattern(patternText, u, v)로 둔다.
  15. parseResultSyntaxError objects의 non-empty List이면, SyntaxError exception을 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를 contain하는 List로 둔다.
  2. Else if vtrue이면, 다음을 수행한다.
    1. parseResultParseText(patternText, Pattern[+UnicodeMode, +UnicodeSetsMode, +NamedCaptureGroups])로 둔다.
  3. Else if utrue이면, 다음을 수행한다.
    1. parseResultParseText(patternText, Pattern[+UnicodeMode, ~UnicodeSetsMode, +NamedCaptureGroups])로 둔다.
  4. Else,
    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로 called될 때 new RegExp object를 create하고 initialize합니다.
  • constructor가 아니라 function으로 called될 때, new RegExp object 또는 only argument가 RegExp object인 경우 argument itself를 반환합니다.
  • class definition의 extends clause의 value로 사용될 수 있습니다. specified RegExp behaviour를 inherit하려는 subclass constructors는 necessary internal slots를 가진 subclass instances를 create하고 initialize하기 위해 RegExp constructor에 대한 super call을 include해야 합니다.

22.2.4.1 RegExp ( patternOrRegexp, flags )

이 function은 called될 때 다음 steps를 수행합니다:

  1. patternIsRegExp를 ? IsRegExp(patternOrRegexp)로 둔다.
  2. NewTarget이 undefined이면, 다음을 수행한다.
    1. newTarget을 active function object로 둔다.
    2. patternIsRegExptrue이고 flagsundefined이면, 다음을 수행한다.
      1. patternCtor를 ? Get(patternOrRegexp, "constructor")로 둔다.
      2. SameValue(newTarget, patternCtor)가 true이면, patternOrRegexp를 반환한다.
  3. Else,
    1. newTarget을 NewTarget으로 둔다.
  4. patternOrRegexp가 Object이고 patternOrRegexp[[RegExpMatcher]] internal slot을 가지면, 다음을 수행한다.
    1. patternSourcepatternOrRegexp.[[OriginalSource]]로 둔다.
    2. flagsundefined이면, flagspatternOrRegexp.[[OriginalFlags]]로 설정한다.
  5. Else if patternIsRegExptrue이면, 다음을 수행한다.
    1. patternSource를 ? Get(patternOrRegexp, "source")로 둔다.
    2. flagsundefined이면, 다음을 수행한다.
      1. flags를 ? Get(patternOrRegexp, "flags")로 설정한다.
  6. Else,
    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를 contain해야 한다면, any U+005C (REVERSE SOLIDUS) code points는 StringLiteral의 contents가 formed될 때 removed되는 것을 prevent하기 위해 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로 replaced된 string의 copy를 반환합니다.

called될 때 다음 steps를 수행합니다:

  1. string이 String이 아니면, TypeError exception을 throw한다.
  2. escaped를 empty String으로 둔다.
  3. codePointListStringToCodePoints(string)로 둔다.
  4. codePointList의 각 code point codePoint에 대해, 다음을 수행한다.
    1. escaped가 empty String이고 codePointDecimalDigit 또는 AsciiLetter에 의해 matched되면, 다음을 수행한다.
      1. NOTE: leading digit를 escaping하면 output이 \0 character escape 또는 \1 같은 DecimalEscape 뒤에서 사용될 수 있는 pattern text와 correspond하고, preceding escape sequence의 extension으로 interpreted되는 대신 still string을 match하게 된다. leading ASCII letter를 escaping하는 것도 \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. Else,
      1. escapedescapedEncodeForRegExpEscape(codePoint)의 string-concatenation으로 설정한다.
  5. escaped를 반환한다.
Note

similar names를 가지고 있음에도, EscapeRegExpPatternRegExp.escape는 similar actions를 수행하지 않습니다. former는 string으로 representation하기 위해 pattern을 escapes하는 반면, 이 function은 pattern 안에서 representation하기 위해 string을 escapes합니다.

22.2.5.1.1 EncodeForRegExpEscape ( codePoint )

The abstract operation EncodeForRegExpEscape takes argument codePoint (a code point) and returns a String. codePoint를 matching하기 위한 Pattern을 representing하는 String을 반환합니다. codePoint가 white space 또는 ASCII punctuator이면, returned value는 escape sequence입니다. Otherwise, returned value는 codePoint itself의 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를 contain하는 row의 “ControlEscape” column 안의 string의 string-concatenation을 반환한다.
  3. otherPunctuators",-=<>#&!%:;@~'`"와 code unit 0x0022 (QUOTATION MARK)의 string-concatenation으로 둔다.
  4. toEscapeStringToCodePoints(otherPunctuators)로 둔다.
  5. toEscapecodePoint를 contain하거나, 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이 undefinedaccessor property입니다. Its get accessor function은 called될 때 다음 steps를 수행합니다:

  1. this value를 반환한다.

이 function의 "name" property의 value는 "get [Symbol.species]"입니다.

Note

RegExp prototype methods는 normally their this value의 constructor를 사용하여 derived object를 create합니다. However, subclass constructor는 its %Symbol.species% property를 redefining하여 that 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의 any other internal slots를 가지지 않습니다.
  • value가 %Object.prototype%[[Prototype]] internal slot을 가집니다.
Note

RegExp prototype object는 its own "valueOf" property를 가지지 않습니다; however, Object prototype object로부터 "valueOf" property를 inherits합니다.

22.2.6.1 RegExp.prototype.constructor

RegExp.prototype.constructor의 initial value는 %RegExp%입니다.

22.2.6.2 RegExp.prototype.exec ( string )

이 method는 regular expression pattern의 occurrence를 string에서 searches하고 match의 results를 contain하는 Array 또는 string이 match하지 않은 경우 null을 반환합니다.

called될 때 다음 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이 undefinedaccessor property입니다. Its get accessor function은 called될 때 다음 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이 undefinedaccessor property입니다. Its get accessor function은 called될 때 다음 steps를 수행합니다:

  1. regexpthis value로 둔다.
  2. regexp가 Object가 아니면, TypeError exception을 throw한다.
  3. codeUnits를 새 empty 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이 returned된다.

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 exception을 throw한다.
  2. regexp[[OriginalFlags]] internal slot을 가지지 않으면, 다음을 수행한다.
    1. SameValue(regexp, %RegExp.prototype%)가 true이면, undefined를 반환한다.
    2. TypeError exception을 throw한다.
  3. flagsregexp.[[OriginalFlags]]로 둔다.
  4. flagscodeUnit을 contain하면, true를 반환한다.
  5. false를 반환한다.

22.2.6.5 get RegExp.prototype.global

RegExp.prototype.global은 set accessor function이 undefinedaccessor property입니다. Its get accessor function은 called될 때 다음 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이 undefinedaccessor property입니다. Its get accessor function은 called될 때 다음 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이 undefinedaccessor property입니다. Its get accessor function은 called될 때 다음 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는 called될 때 다음 steps를 수행합니다:

  1. regexpthis value로 둔다.
  2. regexp가 Object가 아니면, TypeError exception을 throw한다.
  3. string을 ? ToString(string)으로 설정한다.
  4. flags를 ? ToString(? Get(regexp, "flags"))로 둔다.
  5. flags"g"를 contain하지 않으면, ? RegExpExec(regexp, string)를 반환한다.
  6. flags"u"를 contain하거나 flags"v"를 contain하면 fullUnicodetrue로 둔다; else fullUnicodefalse로 둔다.
  7. Set(regexp, "lastIndex", +0𝔽, true)를 수행한다.
  8. array를 ! ArrayCreate(0)으로 둔다.
  9. matchCount를 0으로 둔다.
  10. Repeat,
    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 또는 Boolean coerce to true하지 않는 value를 가진 such property의 existence는 object가 regular expression object로 used될 intended가 아님을 indicates합니다.

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

이 method는 called될 때 다음 steps를 수행합니다:

  1. regexpthis value로 둔다.
  2. regexp가 Object가 아니면, TypeError exception을 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"를 contain하면, globaltrue로 둔다.
  10. Else, globalfalse로 둔다.
  11. flags"u"를 contain하거나 flags"v"를 contain하면, fullUnicodetrue로 둔다.
  12. Else, 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이 undefinedaccessor property입니다. Its get accessor function은 called될 때 다음 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는 called될 때 다음 steps를 수행합니다:

  1. regexpthis value로 둔다.
  2. regexp가 Object가 아니면, TypeError exception을 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"를 contain하면 globaltrue로 둔다; else globalfalse로 둔다.
  9. globaltrue이면, 다음을 수행한다.
    1. Set(regexp, "lastIndex", +0𝔽, true)를 수행한다.
  10. results를 새 empty List로 둔다.
  11. donefalse로 둔다.
  12. Repeat, while done is false,
    1. result를 ? RegExpExec(regexp, string)로 둔다.
    2. resultnull이면, 다음을 수행한다.
      1. donetrue로 설정한다.
    3. Else,
      1. resultresults에 append한다.
      2. globalfalse이면, 다음을 수행한다.
        1. donetrue로 설정한다.
      3. Else,
        1. matchString을 ? ToString(? Get(result, "0"))으로 둔다.
        2. matchString이 empty String이면, 다음을 수행한다.
          1. thisIndex(? ToLength(? Get(regexp, "lastIndex")))로 둔다.
          2. flags"u"를 contain하거나 flags"v"를 contain하면 fullUnicodetrue로 둔다; else fullUnicodefalse로 둔다.
          3. nextIndexAdvanceStringIndex(string, thisIndex, fullUnicode)로 둔다.
          4. Set(regexp, "lastIndex", 𝔽(nextIndex), true)를 수행한다.
  13. accumulatedResult를 empty String으로 둔다.
  14. nextSourcePosition을 0으로 둔다.
  15. results의 각 element 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를 새 empty List로 둔다.
    8. captureNumber를 1로 둔다.
    9. Repeat, while 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 안에 넣는다(index 0에). More generally, 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. Else,
      1. namedCapturesundefined가 아니면, 다음을 수행한다.
        1. namedCaptures를 ? ToObject(namedCaptures)로 설정한다.
      2. replacementString을 ? GetSubstitution(matched, string, position, captures, namedCaptures, replaceValue)로 둔다.
    13. positionnextSourcePosition이면, 다음을 수행한다.
      1. NOTE: position은 normally backwards로 move해서는 안 된다. 그렇게 된다면, ill-behaving RegExp subclass 또는 global flag나 regexp의 other characteristics를 change하는 access triggered side-effect의 사용을 indication한다. such cases에서, corresponding substitution은 ignored된다.
      2. accumulatedResultaccumulatedResult, stringnextSourcePosition부터 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는 called될 때 다음 steps를 수행합니다:

  1. regexpthis value로 둔다.
  2. regexp가 Object가 아니면, TypeError exception을 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를 performing할 때 ignored됩니다. "lastIndex" property는 unchanged로 남습니다.

22.2.6.13 get RegExp.prototype.source

RegExp.prototype.source는 set accessor function이 undefinedaccessor property입니다. Its get accessor function은 called될 때 다음 steps를 수행합니다:

  1. regexpthis value로 둔다.
  2. regexp가 Object가 아니면, TypeError exception을 throw한다.
  3. regexp[[OriginalSource]] internal slot을 가지지 않으면, 다음을 수행한다.
    1. SameValue(regexp, %RegExp.prototype%)가 true이면, "(?:)"를 반환한다.
    2. TypeError exception을 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"를 contain하면, 다음을 수행한다.
    1. patternSymbolPattern[+UnicodeMode, +UnicodeSetsMode]로 둔다.
  2. Else if flags"u"를 contain하면, 다음을 수행한다.
    1. patternSymbolPattern[+UnicodeMode, ~UnicodeSetsMode]로 둔다.
  3. Else,
    1. patternSymbolPattern[~UnicodeMode, ~UnicodeSetsMode]로 둔다.
  4. escapedPattern을 UTF-16 encoded Unicode code points(6.1.4)로 interpreted된 pattern과 equivalent한 patternSymbol의 form인 String으로 두며, 그 안에서 certain code points는 below에 described된 대로 escaped된다. escapedPatternpattern과 differ할 수도 있고 differ하지 않을 수도 있다; however, escapedPatternpatternSymbol로 evaluating하여 result하는 Abstract Closure는 constructed object의 [[RegExpMatcher]] internal slot이 given하는 Abstract Closure와 identically behave해야 한다. same values for pattern and flags를 사용하여 이 abstract operation을 multiple calls하면 identical results를 produce해야 한다.
  5. pattern 안에 occurring하는 code points / 또는 any LineTerminatorescapedPattern 안에서, "/", escapedPattern, "/", 및 flagsstring-concatenation이 constructed regular expression과 identically behave하는 RegularExpressionLiteral로(in an appropriate lexical context) parsed될 수 있도록 necessary하게 escaped되어야 한다. 예를 들어, pattern"/"이면 escapedPattern은 among other possibilities "\/" 또는 "\u002F"일 수 있지만, "/"일 수는 없다. 왜냐하면 flags가 followed되는 ///RegularExpressionLiteral이 아니라 SingleLineComment로 parsed될 것이기 때문이다. pattern이 empty String이면, 이 specification은 escapedPattern"(?:)"로 두어 met될 수 있다.
  6. escapedPattern을 반환한다.
Note

similar names를 가지고 있음에도, RegExp.escape와 EscapeRegExpPattern은 similar actions를 수행하지 않습니다. former는 pattern 안에서 representation하기 위해 string을 escapes하는 반면, 이 function은 string으로 representation하기 위해 pattern을 escapes합니다.

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로 searching하여 determined됩니다; 이러한 occurrences는 returned array 안의 any String의 part가 아니지만, String value를 divide up하는 역할을 합니다.

this value는 empty regular expression 또는 empty String을 match할 수 있는 regular expression일 수 있습니다. 이 경우, 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와 equal하고, 각 substring은 one code unit을 contain합니다.) backtracking이 해당 index에서 non-empty substring match를 yield할 수 있더라도, String의 given index에서 first match만 considered됩니다. (예를 들어, /a*?/[Symbol.split]("ab")는 array ["a", "b"]로 evaluates되는 반면, /a*/[Symbol.split]("ab")는 array ["","b"]로 evaluates됩니다.)

string이 empty String이거나 empty String으로 converts되면, result는 regular expression이 empty String을 match할 수 있는지 여부에 depends합니다. match할 수 있으면, result array는 no elements를 contain합니다. Otherwise, result array는 one element를 contain하며, 이는 empty String입니다.

regular expression이 capturing parentheses를 contain하면, separator가 matched될 때마다 capturing parentheses의 results(any 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는 no more than limit elements를 contain하도록 truncated됩니다.

이 method는 called될 때 다음 steps를 수행합니다:

  1. regexpthis value로 둔다.
  2. regexp가 Object가 아니면, TypeError exception을 throw한다.
  3. string을 ? ToString(string)으로 설정한다.
  4. speciesCtor를 ? SpeciesConstructor(regexp, %RegExp%)로 둔다.
  5. flags를 ? ToString(? Get(regexp, "flags"))로 둔다.
  6. flags"u"를 contain하거나 flags"v"를 contain하면, unicodeMatchingtrue로 둔다.
  7. Else, unicodeMatchingfalse로 둔다.
  8. flags"y"를 contain하면, newFlagsflags로 둔다.
  9. Else, newFlagsflags"y"string-concatenation으로 둔다.
  10. splitter를 ? Construct(speciesCtor, « regexp, newFlags »)로 둔다.
  11. array를 ! ArrayCreate(0)으로 둔다.
  12. lengthA를 0으로 둔다.
  13. limitundefined이면 lim을 232 - 1로 둔다; else 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. Repeat, while searchIndex < size,
    1. Set(splitter, "lastIndex", 𝔽(searchIndex), true)를 수행한다.
    2. matchResult를 ? RegExpExec(splitter, string)로 둔다.
    3. matchResultnull이면, 다음을 수행한다.
      1. searchIndexAdvanceStringIndex(string, searchIndex, unicodeMatching)로 설정한다.
    4. Else,
      1. matchEnd(? ToLength(? Get(splitter, "lastIndex")))로 둔다.
      2. matchEndmin(matchEnd, size)로 설정한다.
      3. matchEnd = lastMatchEnd이면, 다음을 수행한다.
        1. searchIndexAdvanceStringIndex(string, searchIndex, unicodeMatching)로 설정한다.
      4. Else,
        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. Repeat, while 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를 ignores합니다.

22.2.6.15 get RegExp.prototype.sticky

RegExp.prototype.sticky는 set accessor function이 undefinedaccessor property입니다. Its get accessor function은 called될 때 다음 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는 called될 때 다음 steps를 수행합니다:

  1. regexpthis value로 둔다.
  2. regexp가 Object가 아니면, TypeError exception을 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 exception을 throw한다.
  3. pattern을 ? ToString(? Get(regexp, "source"))으로 둔다.
  4. flags를 ? ToString(? Get(regexp, "flags"))로 둔다.
  5. result"/", pattern, "/", 및 flagsstring-concatenation으로 둔다.
  6. result를 반환한다.
Note

returned String은 this object와 same behaviour를 가진 another RegExp object로 evaluates되는 RegularExpressionLiteral의 form을 가집니다.

22.2.6.18 get RegExp.prototype.unicode

RegExp.prototype.unicode는 set accessor function이 undefinedaccessor property입니다. Its get accessor function은 called될 때 다음 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이 undefinedaccessor property입니다. Its get accessor function은 called될 때 다음 steps를 수행합니다:

  1. regexpthis value로 둔다.
  2. codeUnit을 code unit 0x0076 (LATIN SMALL LETTER V)로 둔다.
  3. RegExpHasFlag(regexp, codeUnit)를 반환한다.

22.2.7 RegExp Matching용 Abstract Operations

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 exception을 throw한다.
    3. result를 반환한다.
  3. RequireInternalSlot(regexp, [[RegExpMatcher]])를 수행한다.
  4. RegExpBuiltinExec(regexp, string)를 반환한다.
Note

callable "exec" property가 found되지 않으면 이 algorithm은 built-in RegExp matching algorithm 사용을 attempt하는 것으로 fallback합니다. 이는 regular expressions를 사용하는 most built-in algorithms가 "exec"의 dynamic property lookup을 수행하지 않았던 prior editions용으로 written된 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"를 contain하면 globaltrue로 둔다; else globalfalse로 둔다.
  5. flags"y"를 contain하면 stickytrue로 둔다; else stickyfalse로 둔다.
  6. flags"d"를 contain하면 hasIndicestrue로 둔다; else hasIndicesfalse로 둔다.
  7. globalfalse이고 stickyfalse이면, lastIndex를 0으로 설정한다.
  8. matcherregexp.[[RegExpMatcher]]로 둔다.
  9. flags"u"를 contain하거나 flags"v"를 contain하면 fullUnicodetrue로 둔다; else fullUnicodefalse로 둔다.
  10. matchSucceededfalse로 둔다.
  11. fullUnicodetrue이면 inputStringToCodePoints(string)로 둔다; else input을 elements가 string의 elements인 code units인 List로 둔다.
  12. NOTE: input의 각 element는 character로 considered된다.
  13. Repeat, while matchSucceeded is false,
    1. lastIndex > length이면, 다음을 수행한다.
      1. globaltrue이거나 stickytrue이면, 다음을 수행한다.
        1. Set(regexp, "lastIndex", +0𝔽, true)를 수행한다.
      2. null을 반환한다.
    2. inputIndexstring의 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. Else,
      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를 새 empty List로 둔다.
  26. groupNames를 새 empty List로 둔다.
  27. matchindices에 append한다.
  28. matchedSubstringGetMatchString(string, match)로 둔다.
  29. CreateDataPropertyOrThrow(array, "0", matchedSubstring)를 수행한다.
  30. regexp가 any GroupName을 contain하면, 다음을 수행한다.
    1. groupsOrdinaryObjectCreate(null)로 둔다.
    2. hasGroupstrue로 둔다.
  31. Else,
    1. groupsundefined로 둔다.
    2. hasGroupsfalse로 둔다.
  32. CreateDataPropertyOrThrow(array, "groups", groups)를 수행한다.
  33. matchedGroupNames를 새 empty List로 둔다.
  34. 1 ≤ icapturingGroupsCount를 만족하는 각 integer i에 대해, ascending order로, 다음을 수행한다.
    1. captureresult.[[Captures]]ith element로 둔다.
    2. captureundefined이면, 다음을 수행한다.
      1. capturedValueundefined로 둔다.
      2. undefinedindices에 append한다.
    3. Else,
      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을 that GroupNameCapturingGroupName으로 둔다.
      2. matchedGroupNamesgroupName을 contain하면, 다음을 수행한다.
        1. Assert: capturedValueundefined이다.
        2. undefinedgroupNames에 append한다.
      3. Else,
        1. capturedValueundefined가 아니면, groupNamematchedGroupNames에 append한다.
        2. NOTE: groupName이라고 named된 multiple groups가 있으면, groups는 이 point에서 이미 groupName property를 가지고 있을 수 있다. However, groups가 properties가 모두 writable data propertiesordinary object이므로, CreateDataPropertyOrThrow call은 nevertheless succeed하는 것이 guaranteed된다.
        3. CreateDataPropertyOrThrow(groups, groupName, capturedValue)를 수행한다.
        4. groupNamegroupNames에 append한다.
    6. Else,
      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하고, such index가 exist할 때 code point index codePointIndex에 corresponding하는 code unit index를 반환합니다. Otherwise, string의 length를 반환합니다. It performs the following steps when called:

  1. string이 empty String이면, 0을 반환한다.
  2. lengthstring의 length로 둔다.
  3. codeUnitCount를 0으로 둔다.
  4. codePointCount를 0으로 둔다.
  5. Repeat, while 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를 contain한다.
  5. array를 ! ArrayCreate(n)로 둔다.
  6. hasGroupstrue이면, 다음을 수행한다.
    1. groupsOrdinaryObjectCreate(null)로 둔다.
  7. Else,
    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. Else,
      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는 이 point에서 이미 name property를 가지고 있을 수 있다. However, groups가 properties가 모두 writable data propertiesordinary object이므로, CreateDataPropertyOrThrow call은 nevertheless succeed하는 것이 guaranteed된다.
        3. CreateDataPropertyOrThrow(groups, name, matchIndexPair)를 수행한다.
  10. array를 반환한다.

22.2.8 RegExp Instances의 Properties

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되었습니다. Those properties는 now RegExp.prototypeaccessor properties로 specified됩니다.

RegExp instances는 또한 다음 property를 가집니다:

22.2.8.1 lastIndex

"lastIndex" property의 value는 next match를 start할 String index를 specifies합니다. 사용될 때 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 String instance object에 대한 specific iteration을 represent하고, some specific RegExp instance object에 대해 matching하는 object입니다. RegExp String Iterator objects를 위한 named constructor는 없습니다. 대신, RegExp String Iterator objects는 RegExp instance objects의 certain methods를 calling하여 created됩니다.

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 exception을 throw한다.
  3. iteratorObjRegExp String Iterator Object Instance의 all internal slots(22.2.9.3 참조)를 가지지 않으면, TypeError exception을 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 RegExp String Iterator Instances의 Properties

RegExp String Iterator instances는 %RegExpStringIteratorPrototype% intrinsic object로부터 properties를 inherit하는 ordinary objects입니다. RegExp String Iterator instances는 Table 69에 listed된 internal slots로 initially created됩니다.

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 iterated upon되고 있는 String value입니다.
[[Global]] a Boolean [[IteratingRegExp]]가 global인지 여부를 indicate합니다.
[[Unicode]] a Boolean [[IteratingRegExp]]가 Unicode mode인지 여부를 indicate합니다.
[[Done]] a Boolean iteration이 complete되었는지 여부를 indicate합니다.