Skip to content

fix: support d, s, u, and v flags in regexp/regexp - #16543

Open
rajanpanth wants to merge 1 commit into
stdlib-js:developfrom
rajanpanth:fix/regexp-regexp-flags
Open

rajanpanth wants to merge 1 commit into
stdlib-js:developfrom
rajanpanth:fix/regexp-regexp-flags

Conversation

@rajanpanth

Copy link
Copy Markdown

Description

What is the purpose of this pull request?

This pull request:

  • adds the d, s, u, and v flags to the flags accepted by regexp/regexp. The regular expression only accepted imgy, so a regular expression string using any other standard flag was not recognized:

    var reFromString = require( '@stdlib/utils/regexp-from-string' );
    var isRegExpString = require( '@stdlib/assert/is-regexp-string' );
    
    reFromString( '/\\p{L}+/u' );
    // returns null (expected /\p{L}+/u)
    
    reFromString( '/a.b/s' );
    // returns null (expected /a.b/s)
    
    isRegExpString( '/beep/gimsuy' );
    // returns false (expected true)

    u and y were added in ES2015, s in ES2018, d in ES2022, and v in ES2024.

  • updates the documented regular expression in lib/regexp.js to match.

  • adds tests to regexp/regexp for strings with each newly accepted flag, and a test to utils/regexp-from-string checking that each flag supported by the current environment round-trips.

Related Issues

Does this pull request have any related issues?

None.

Questions

Any questions for reviewers of this pull request?

The pattern still accepts a repeated flag (e.g., /beep/gg), as it did before for imgy; reFromString then throws when constructing the regular expression. I left this behavior unchanged to keep the change focused. Happy to tighten the pattern to reject repeated flags if preferred.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

  • Packages using regexp/regexp (e.g., utils/regexp-from-string and assert/is-regexp-string) pick up the change without modification, and their existing tests pass.
  • In an environment that does not support a given flag, reFromString now throws when constructing the regular expression, rather than returning null. For this reason, the new utils/regexp-from-string test only checks flags that new RegExp() accepts in the current environment.
  • The new regexp/regexp tests fail on develop (6 assertions in each of test.main.js and test.regexp.js), as does the new utils/regexp-from-string test.
  • I ran the tests for regexp/regexp, utils/regexp-from-string, and assert/is-regexp-string directly with Node.js and tape on Windows (as make was not available in my environment); I did not run the full repository lint pipeline locally.

Checklist

Please ensure the following tasks are completed before submitting this pull request.

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

If you answered "yes" to using AI assistance, please provide a short disclosure indicating how you used AI assistance. This helps reviewers determine how much scrutiny to apply when reviewing your contribution. Example disclosures: "This PR was written primarily by Claude Code." or "I consulted ChatGPT to understand the codebase, but the proposed changes were fully authored manually by myself.".

This PR was written with the help of Claude Code, which found the issue, drafted the change and tests, and ran the verification described above. I reviewed the changes and the test results before submitting.


@stdlib-js/reviewers

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rajanpanth
rajanpanth requested a review from a team November 8, 2026 03:50
@stdlib-bot stdlib-bot added Needs Review A pull request which needs code review. First-time Contributor A pull request from a contributor who has never previously committed to the project repository. labels Nov 8, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

First-time Contributor A pull request from a contributor who has never previously committed to the project repository. Needs Review A pull request which needs code review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants