অনুযায়ী ECMA-262 মান String.prototype.replace আহ্বান RegExp.prototype [@@ প্রতিস্থাপন] , যা বলে:
11. Repeat, while done is false
a. Let result be ? RegExpExec(rx, S).
b. If result is null, set done to true.
c. Else result is not null,
i. Append result to the end of results.
ii. If global is false, set done to true.
iii. Else,
1. Let matchStr be ? ToString(? Get(result, "0")).
2. If matchStr is the empty String, then
a. Let thisIndex be ? ToLength(? Get(rx, "lastIndex")).
b. Let nextIndex be AdvanceStringIndex(S, thisIndex, fullUnicode).
c. Perform ? Set(rx, "lastIndex", nextIndex, true).
যেখানে rxহয় /.*/gএবং Sহয় 'asdf'।
11.c.iii.2.b দেখুন:
খ। নেক্সটইন্ডেক্সকে অ্যাডভান্সস্ট্রিংইন্ডেক্স (এস, এটিআইডেক্স, ফুল ইউনিকোড) হতে দিন।
সুতরাং 'asdf'.replace(/.*/g, 'x')এটি আসলে:
- ফলাফল (
[]অপরিজ্ঞাত ), ফলাফল = , সর্বশেষ তালিকা =0
- ফলাফল =
'asdf', ফলাফলগুলি = [ 'asdf' ], সর্বশেষ তালিকা =4
- ফলাফলের =
'', ফলাফল = [ 'asdf', '' ], lastIndex = 4, AdvanceStringIndex, lastIndex সেট5
- ফলাফল =
null, ফলাফল = [ 'asdf', '' ], প্রত্যাবর্তন
সুতরাং 2 টি ম্যাচ আছে।
"asdf".match(/.*/g)ফিরে ["এসএসডিএফ", ""]