Skip to content

refactor(web): replace String.match() with RegExp.exec() for non-global regex#32386

Merged
asukaminato0721 merged 1 commit intolanggenius:mainfrom
apoorvdarshan:refactor/replace-string-match-with-regexp-exec
Feb 18, 2026
Merged

refactor(web): replace String.match() with RegExp.exec() for non-global regex#32386
asukaminato0721 merged 1 commit intolanggenius:mainfrom
apoorvdarshan:refactor/replace-string-match-with-regexp-exec

Conversation

@apoorvdarshan
Copy link
Contributor

Summary

  • Replace string.match(regex) with regex.exec(string) across 18 files (~22 occurrences) per SonarQube rule S6594
  • When String#match is called without the global flag, it internally delegates to RegExp#exec, so calling exec() directly is more explicit and avoids the indirection
  • All .match() calls using global (g) flag regexes are intentionally left unchanged as they have different return semantics (returning all matches)

Closes #25199

Test plan

  • Run pnpm lint — no new lint errors
  • Run pnpm type-check:tsgo — no type errors
  • Run pnpm test — all existing tests pass
  • Verify skipped files still use .match() with global regex (e.g., block-input/index.tsx:16, mermaid/index.tsx:251)

Copilot AI review requested due to automatic review settings February 17, 2026 22:30
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. refactor labels Feb 17, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @apoorvdarshan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors regular expression usage across the codebase by standardizing the approach for non-global regex matching. The change improves code clarity and aligns with best practices by directly using RegExp.exec() instead of String.match() when the global flag is not present, enhancing maintainability and addressing a SonarQube recommendation.

Highlights

  • Refactor Regex Usage: Replaced String.match() with RegExp.exec() for non-global regular expressions across 18 files and approximately 22 occurrences.
  • SonarQube Rule Adherence: Addressed SonarQube rule S6594 to improve code explicitness and avoid indirection when performing regex matches.
  • Preserved Global Regex Behavior: Intentionally left String.match() calls using global (g) flag regexes unchanged due to their distinct return semantics.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • web/tests/check-i18n.test.ts
    • Replaced match() with exec() for regex comparisons.
  • web/app/components/app/configuration/index.tsx
    • Updated regex matching for pathname.
  • web/app/components/base/block-input/index.tsx
    • Changed regex matching for variable extraction.
  • web/app/components/base/chat/chat/answer/human-input-content/content-item.tsx
    • Modified regex usage for field name extraction.
  • web/app/components/base/date-and-time-picker/utils/dayjs.ts
    • Replaced match() with exec() for offset string parsing.
  • web/app/components/base/features/new-feature-panel/annotation-reply/index.tsx
    • Updated regex matching for pathname.
  • web/app/components/base/features/new-feature-panel/text-to-speech/param-config-content.tsx
    • Updated regex matching for pathname.
  • web/app/components/base/ga/index.tsx
    • Changed regex matching for nonce extraction from CSP header.
  • web/app/components/base/mermaid/index.tsx
    • Replaced match() with exec() for task line parsing in Gantt charts.
  • web/app/components/base/mermaid/utils.ts
    • Updated regex matching for syntax error checking.
  • web/app/components/billing/utils/index.ts
    • Modified regex for parsing vector space units.
  • web/app/components/datasets/common/tests/credential-icon.spec.tsx
    • Replaced match() with exec() for background class extraction in tests.
  • web/app/components/tools/mcp/hooks/use-mcp-modal-form.ts
    • Updated regex for file ID extraction from URL.
  • web/scripts/component-analyzer.js
    • Changed regex matching for cognitive complexity pattern.
  • web/scripts/gen-doc-paths.ts
    • Modified regex for language determination from OpenAPI paths.
  • web/utils/error-parser.ts
    • Replaced match() with exec() for plugin error message parsing.
  • web/utils/format.ts
    • Updated regex for scientific notation parsing in number formatting.
  • web/utils/urlValidation.ts
    • Changed regex for IPv4 address matching in URL validation.
Activity
  • Verified no new lint errors by running pnpm lint.
  • Confirmed no type errors by running pnpm type-check:tsgo.
  • Ensured all existing tests pass by running pnpm test.
  • Validated that files with global regexes still use .match(), as intended (e.g., block-input/index.tsx:16, mermaid/index.tsx:251).
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions github-actions bot added the web This relates to changes on the web. label Feb 17, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly refactors String.match() to RegExp.exec() for non-global regular expressions, which is a good practice for explicitness and performance. The changes are applied consistently across all relevant files.

I've added a few suggestions to further improve code maintainability. Specifically, I've pointed out some duplicated logic for extracting the appId from the URL path and suggested creating a custom hook to centralize it. I also noted a duplicated regular expression in a test file that could be extracted into a constant. Overall, this is a solid refactoring.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors string matching operations across 18 files to replace String.match() with RegExp.exec() for non-global regex patterns, following SonarQube rule S6594. This change eliminates indirection since String.match() internally delegates to RegExp.exec() when the global flag is not used.

Changes:

  • Replaced string.match(regex) with regex.exec(string) in ~22 locations across utility functions, components, and tests
  • Intentionally preserved .match() calls that use the global flag (e.g., /pattern/g) as they have different return semantics

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
web/utils/urlValidation.ts Updated IPv4 address matching in private IP check
web/utils/format.ts Updated scientific notation detection in number formatting
web/utils/error-parser.ts Updated plugin error message extraction
web/scripts/gen-doc-paths.ts Updated language path matching
web/scripts/component-analyzer.js Updated complexity pattern extraction
web/app/components/tools/mcp/hooks/use-mcp-modal-form.ts Updated file ID extraction from URLs
web/app/components/datasets/common/tests/credential-icon.spec.tsx Updated CSS class matching in tests
web/app/components/billing/utils/index.ts Updated vector space unit parsing
web/app/components/base/mermaid/utils.ts Updated mermaid arrow syntax validation
web/app/components/base/mermaid/index.tsx Updated gantt task line parsing
web/app/components/base/ga/index.tsx Updated CSP nonce extraction
web/app/components/base/features/new-feature-panel/text-to-speech/param-config-content.tsx Updated app ID extraction from pathname
web/app/components/base/features/new-feature-panel/annotation-reply/index.tsx Updated app ID extraction from pathname
web/app/components/base/date-and-time-picker/utils/dayjs.ts Updated timezone offset parsing
web/app/components/base/chat/chat/answer/human-input-content/content-item.tsx Updated output variable extraction
web/app/components/base/block-input/index.tsx Updated variable matching in block input
web/app/components/app/configuration/index.tsx Updated app ID extraction from pathname
web/tests/check-i18n.test.ts Updated key line pattern matching

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…al regex

Replace string.match(regex) with regex.exec(string) across 18 files per
SonarQube rule S6594. When match() is called without the global flag, it
internally delegates to exec(), so calling exec() directly is more explicit
and avoids the indirection. Global-flag match() calls are intentionally
left unchanged as they have different semantics.
@apoorvdarshan apoorvdarshan force-pushed the refactor/replace-string-match-with-regexp-exec branch from 44ea999 to 043370a Compare February 17, 2026 23:11
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 18, 2026
@asukaminato0721 asukaminato0721 merged commit 00591a5 into langgenius:main Feb 18, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer refactor size:M This PR changes 30-99 lines, ignoring generated files. web This relates to changes on the web.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Chore/Refactor] use RegExp.exec instead of string.match

3 participants