Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Regexp escape error with Regexp option 'u' and dash in string #701

Open
Assignees
Labels
BugSomething isn't working. DocumentationImprovements, additions, or changes to documentation. wont-fixUnable and/or unwilling to resolve concern due to inapplicability or lack of problem definition.
@mdesantis

Description

Description

Encountered an error while escaping a string containing a - and passing it to Regexp.new() with u flag enabled

Related Issues

No response

Questions

No response

Demo

https://codesandbox.io/s/node-playground-forked-edd4wv?file=/src/index.js

Reproduction

import rescape from "@stdlib/utils-escape-regexp-string";
console.log(new RegExp(rescape("en-US"))); //=> /en\-US/
console.log(new RegExp(rescape("en-US"), "u")); //=> SyntaxError: invalid identity escape in regular expression

Expected Results

console.log(new RegExp(rescape("en-US"), "u")) should print /en-US/

Actual Results

console.log(new RegExp(rescape("en-US"), "u")) raises an error with a message similar to the following:

SyntaxError: Invalid regular expression: /en\-US/: Invalid escape

Version

@stdlib/utils-escape-regexp-string 0.0.9

Environments

Node.js, Firefox, Chrome

Browser Version

No response

Node.js / npm Version

16

Platform

No response

Checklist

  • Read and understood the Code of Conduct.
  • Searched for existing issues and pull requests.

Metadata

Metadata

Labels

BugSomething isn't working. DocumentationImprovements, additions, or changes to documentation. wont-fixUnable and/or unwilling to resolve concern due to inapplicability or lack of problem definition.

Type

Projects

No projects

Milestone

No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      AltStyle によって変換されたページ (->オリジナル) /