Regex tester: add the `v` flag, and step over emoji correctly when it's on

オープン
#491 コメント 4 件 リアクション 0 件 担当者 1 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@tnalbant がすでに取り組んでいます。

2026年11月27日 から。

  • #512 @HiZhenyu による — マージされずにクローズ
  • #526 @tnalbant による — オープン

評価

難易度
3/5
見積もり時間
半日
初心者へのやさしさ
82/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
nextjs, react, typescript
領域
frontend, tooling

調査の方向性

Start in lib/regex-utils.ts: read compileRegex (line 16) and the empty-match step in findMatches (line 49), then add the issue's table rows to lib/__tests__/regex-utils.test.ts near the u flag test (line 53) and watch them fail. Fix the step to re.unicode || re.unicodeSets and make compileRegex reject u+v. Then add the v button with toggleFlag exclusivity in app/(tools)/regex-tester/RegexTesterClient.tsx and its test, and update the flag list in lib/tools.ts (line 717). Done when the table rows match, both buttons show aria-pressed, and lint, test and build pass.

索引モデルが issue の本文から書いたものです。

説明

enhancement good first issue

The flag buttons offer g, i, m, s, u and y (app/(tools)/regex-tester/RegexTesterClient.tsx, lines 7 to 14), but not v (unicodeSets). Every current browser supports it, and patterns like [\p{L}--[a-z]] or \p{RGI_Emoji} only work with it. compileRegex already accepts v (lib/regex-utils.ts, line 17), so it's only missing from the UI.

Adding the button on its own would expose a bug in findMatches. After an empty match it steps forward two code units only when re.unicode is true (line 49), and re.unicode is false for a v regex. So it steps into the middle of an emoji, the engine moves back to the start of it, and the same empty match comes back until the 1,000 limit:

Pattern Flags Text findMatches now Expected
(empty) gu 😀a 3 matches, at 0, 2, 3 the same
(empty) gv 😀a 1,000 matches at index 0, truncated: true 3 matches, at 0, 2, 3
x* gv 😀😀 1,000 matches at index 0 3 matches, at 0, 2, 4
(?:) gv a😀b 1,000 matches, at 0 and then 1 over and over 4 matches, at 0, 1, 3, 4

The replace preview already gets these right, because String.replace handles v itself.

What to do

  • Add a v button after u, with a title like "Unicode sets: set operations and string properties". u and v can't be used together (new RegExp("a", "uv") throws), so turning one on in toggleFlag (line 68) turns the other off.
  • In findMatches, step over a surrogate pair when either flag is set: re.unicode || re.unicodeSets.
  • In compileRegex, reject u and v together with a message about the flags. Today that reaches new RegExp and comes back as "Invalid pattern: Invalid flags supplied to RegExp constructor 'uv'".
  • Add v to the FAQ in lib/tools.ts (line 717) that lists the flags.

Where to look

  • lib/regex-utils.ts: compileRegex (line 16) and findMatches (line 30)
  • lib/__tests__/regex-utils.test.ts, next to the u flag test (line 53)
  • app/(tools)/regex-tester/RegexTesterClient.tsx and RegexTesterClient.test.tsx

Acceptance criteria

  • Every row in the table gives the expected matches
  • There's a v button with aria-pressed like the others, and turning on u or v turns the other off
  • compileRegex("a", "uv") returns an error about the flags
  • Tests that fail on the current code
  • npm run lint, npm run test and npm run build pass

How to test

The table rows go straight into regex-utils.test.ts. For the button, a component test can click u, then v, and check aria-pressed on both. By hand: npm run dev, open /regex-tester, enter the pattern x*, turn on v and paste 😀😀 as the test text. Before the fix it says "More than 1,000 matches, showing the first 1,000"; after it, 3 matches.


Want to work on this? Comment below and I'll assign it to you. Please take one issue at a time, branch off develop, and open your PR against develop with Closes #491 in the description.

主要言語
TypeScript
スター
1
フォーク
9
平均マージ
1日 8時間
マージ済み PR(30日)
49

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

codercops/toolbelt のほかの issue

codercops/toolbelt の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。