X hashtag: #esspec
便利ツール
時事ネタ
ES2026リリース!
JSConf
TSKaigi Sendai 2026
自己紹介 (近況報告)
syumai syumai.icon
TSを書いて暮らしてます
インターネット回線が速くなりました
フレッツ光クロス
iwatsurut
とくに、イベントもなく過ごしています。
igrep(山本悠滋)
関数型まつり 2026 は今週末!資料はまだ出来てない!
6/20 にPC故障からのゲーミングノートPC購入。設定祭りでまた寝不足気味
Zoomの声紋登録も改めてやり直したがどうだ?
maru。(まる)
主にTSで仕事してます。React, Node。
fable使ってずっとやりたかったけどやれてなかった重めのタスクの実装プラン作らせていた(実装と検証とプランニングいったんさせてfable無くなっても大丈夫なように。)
長崎の廃墟行ってました。池島。
yebis0942
Go, TypeScriptで仕事をしてます。
今からFableロスを感じています。
画像処理とかでOpus 4.8が匙を投げた問題を解決してくれた
人間は「賢い…」と言いながらコミットする作業をしていた
同時編集JavaScript Playground
前半
後半
前回のあらすじ
今回のメモ
RegExpのlastIndex
code:js
// ===== Code =====
const str = "foofoofoobarfoo";
const regex = /foo/y;
console.log(regex.test(str)); // true
console.log(regex.lastIndex); // 3
console.log(regex.test(str)); // true
console.log(regex.lastIndex); // 6
console.log(regex.test(str)); // true
console.log(regex.lastIndex); // 9
console.log(regex.test(str)); // false
console.log(regex.lastIndex); // 0
console.log(regex.test(str)); // true
console.log(regex.lastIndex); // 3
// ===== Output =====
true
3
true
6
true
9
false
0
true
3
code:js
// ===== Code =====
const str = "foofoofoobarfoo";
const regex = /foo/y;
console.log(str.search(regex)); // 0
console.log(regex.lastIndex); // 0
console.log(str.search(regex)); // 0
console.log(regex.lastIndex); // 0
// ===== Output =====
0
0
0
0
code:js
// ===== Code =====
const str = "ABCDEABCDE";
console.log(str.replaceAll("BC", "bc"));
console.log(str.replaceAll("", "!"));
console.log(str.replaceAll(new RegExp("", "g"), "!"));
// ===== Output =====
AbcDEAbcDE
!A!B!C!D!E!A!B!C!D!E!
!A!B!C!D!E!A!B!C!D!E!
code:js
// ===== Code =====
{
const str = "ABCDEABCDE";
console.log(
str.replaceAll("CD", function (searchString, matchPosition, string) {
return string
.substring(matchPosition, matchPosition + searchString.length)
.toLowerCase();
}),
);
}
// ===== Output =====
ABcdEABcdE
code:js
// ===== Code =====
{
const input = '<div id="aaa"><span class="bbb"></span></div>';
const re = /<(\/?)(\w+)(?:\s+(\w+)="(^"*?)")?>/g; console.log(
input.replaceAll(re, (search, isStart, element, attribute, value, position, string) => {
return JSON.stringify({
isStart: isStart === "", element, attribute, value
}, null, 2) + "\n";
}),
);
}
// ===== Output =====
{
"isStart": true,
"element": "div",
"attribute": "id",
"value": "aaa"
}
{
"isStart": true,
"element": "span",
"attribute": "class",
"value": "bbb"
}
{
"isStart": false,
"element": "span"
}
{
"isStart": false,
"element": "div"
}
code:js
// ===== Code =====
const str = "ABCDEABCDE";
console.log(str.replaceAll("BC", "$&")); // ===== Output =====
code:js
// ===== Code =====
{
const s = "ECMAScript";
console.log(s.slice(0));
console.log(s.slice(-Infinity));
console.log(s.slice(0, 4));
console.log(s.slice(4, 100));
console.log(s.slice(-6));
console.log(s.slice(-6, -5));
console.log(s.slice(-6, Infinity));
}
{
console.log(String.prototype.slice.call({}, 1, 7));
}
{
class Hoge {}
console.log(String.prototype.slice.call(new Date(), 1, 7));
console.log(String.prototype.slice.call(new Date(), 0, 3));
console.log(String.prototype.slice.call(new Hoge(), 0, 3));
}
// ===== Output =====
ECMAScript
ECMAScript
ECMA
Script
Script
S
Script
object
ue Jul
Tue
[ob
code:substring-vs-substr.js