Escape a regular expression string or pattern.
Installations
npm install @stdlib/utils-escape-regexp-string
Developer Guide
Typescript
Yes
Module System
CommonJS
Min. Node Version
>=0.10.0
Node Version
16.20.2
NPM Version
8.19.4
Score
99.5
Supply Chain
93.8
Quality
83
Maintenance
100
Vulnerability
88
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
Download Statistics
Total Downloads
72,803,051
Last Day
83,947
Last Week
360,756
Last Month
1,602,652
Last Year
29,395,570
GitHub Statistics
2 Stars
65 Commits
3 Watching
5 Branches
11 Contributors
Bundle Size
8.92 kB
Minified
2.80 kB
Minified + Gzipped
Sponsor this package
Package Meta Information
Latest Version
0.2.2
Package Id
@stdlib/utils-escape-regexp-string@0.2.2
Unpacked Size
28.15 kB
Size
8.67 kB
File Count
11
NPM Version
8.19.4
Node Version
16.20.2
Publised On
27 Jul 2024
Total Downloads
Cumulative downloads
Total Downloads
72,803,051
Last day
-6.2%
83,947
Compared to previous day
Last week
-13.5%
360,756
Compared to previous week
Last month
11.7%
1,602,652
Compared to previous month
Last year
-12.6%
29,395,570
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
About stdlib...
We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.
The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.
When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.
To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!
rescape
Escape a regular expression string or pattern.
Installation
1npm install @stdlib/utils-escape-regexp-string
Usage
1var rescape = require( '@stdlib/utils-escape-regexp-string' );
rescape( str )
Escapes a regular expression string
or pattern.
1var str = rescape( '/[A-Z]*/' ); 2// returns '/\\[A\\-Z\\]\\*/' 3 4str = rescape( '[A-Z]*' ); 5// returns '\\[A\\-Z\\]\\*'
If provided a value which is not a primitive string
, the function throws a TypeError
.
1try { 2 rescape( null ); 3 // throws an error... 4} catch ( err ) { 5 console.error( err ); 6}
-
The following characters have special meaning inside of regular expressions and need to be escaped in case the characters should be treated literally:
description value Backslash \
Braces { }
Brackets [ ]
Caret ^
Dollar Sign $
Forward Slash /
Asterisk *
Parentheses ( )
Period .
Plus Sign +
Vertical Bar |
Question Mark ?
Examples
1var rescape = require( '@stdlib/utils-escape-regexp-string' ); 2 3var out = rescape( '/beep/' ); 4// returns '/beep/' 5 6out = rescape( 'beep' ); 7// returns 'beep' 8 9out = rescape( '/[A-Z]*/' ); 10// returns '/\\[A\\-Z\\]\\*/' 11 12out = rescape( '[A-Z]*' ); 13// returns '\\[A\\-Z\\]\\*' 14 15out = rescape( '/\\\//ig' ); 16// returns '/\\\\\\\//ig' 17 18out = rescape( '\\\/' ); 19// returns '\\\\\\\/' 20 21out = rescape( '/[A-Z]{0,}/' ); 22// returns '/\\[A\\-Z\\]\\{0,\\}/' 23 24out = rescape( '[A-Z]{0,}' ); 25// returns '\\[A\\-Z\\]\\{0,\\}' 26 27out = rescape( '/^boop$/' ); 28// returns '/\\^boop\\$/' 29 30out = rescape( '^boop$' ); 31// returns '\\^boop\\$' 32 33out = rescape( '/(?:.*)/' ); 34// returns '/\\(\\?:\\.\\*\\)/' 35 36out = rescape( '(?:.*)' ); 37// returns '\\(\\?:\\.\\*\\)' 38 39out = rescape( '/(?:beep|boop)/' ); 40// returns '/\\(\\?:beep\\|boop\\)/' 41 42out = rescape( '(?:beep|boop)' ); 43// returns '\\(\\?:beep\\|boop\\)'
Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2024. The Stdlib Authors.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0
Reason
no dangerous workflow patterns detected
Reason
security policy file detected
Details
- Info: security policy file detected: SECURITY.md:1
- Info: Found linked content: SECURITY.md:1
- Warn: One or no descriptive hints of disclosure, vulnerability, and/or timelines in security policy
- Info: Found text in security policy: SECURITY.md:1
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/productionize.yml:275: update your workflow using https://app.stepsecurity.io/secureworkflow/stdlib-js/utils-escape-regexp-string/productionize.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/productionize.yml:449: update your workflow using https://app.stepsecurity.io/secureworkflow/stdlib-js/utils-escape-regexp-string/productionize.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/productionize.yml:457: update your workflow using https://app.stepsecurity.io/secureworkflow/stdlib-js/utils-escape-regexp-string/productionize.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/productionize.yml:623: update your workflow using https://app.stepsecurity.io/secureworkflow/stdlib-js/utils-escape-regexp-string/productionize.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/productionize.yml:85: update your workflow using https://app.stepsecurity.io/secureworkflow/stdlib-js/utils-escape-regexp-string/productionize.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/benchmark.yml:58
- Warn: npmCommand not pinned by hash: .github/workflows/benchmark.yml:58
- Warn: npmCommand not pinned by hash: .github/workflows/benchmark.yml:58
- Warn: npmCommand not pinned by hash: .github/workflows/examples.yml:58
- Warn: npmCommand not pinned by hash: .github/workflows/examples.yml:58
- Warn: npmCommand not pinned by hash: .github/workflows/examples.yml:58
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:436
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:436
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:436
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:617
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:617
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:617
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:157
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:157
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:157
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:165
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:269
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:269
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:269
- Warn: npmCommand not pinned by hash: .github/workflows/test.yml:76
- Warn: npmCommand not pinned by hash: .github/workflows/test.yml:76
- Warn: npmCommand not pinned by hash: .github/workflows/test.yml:76
- Warn: npmCommand not pinned by hash: .github/workflows/test.yml:83
- Warn: npmCommand not pinned by hash: .github/workflows/test_bundles.yml:72
- Warn: npmCommand not pinned by hash: .github/workflows/test_coverage.yml:67
- Warn: npmCommand not pinned by hash: .github/workflows/test_coverage.yml:67
- Warn: npmCommand not pinned by hash: .github/workflows/test_coverage.yml:67
- Warn: npmCommand not pinned by hash: .github/workflows/test_coverage.yml:74
- Warn: npmCommand not pinned by hash: .github/workflows/test_install.yml:75
- Warn: npmCommand not pinned by hash: .github/workflows/test_install.yml:75
- Warn: npmCommand not pinned by hash: .github/workflows/test_install.yml:75
- Warn: npmCommand not pinned by hash: .github/workflows/test_published_package.yml:93
- Info: 33 out of 33 GitHub-owned GitHubAction dependencies pinned
- Info: 19 out of 24 third-party GitHubAction dependencies pinned
- Info: 0 out of 32 npmCommand dependencies pinned
Reason
2 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 1
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/benchmark.yml:1
- Warn: no topLevel permission defined: .github/workflows/cancel.yml:1
- Warn: no topLevel permission defined: .github/workflows/close_pull_requests.yml:1
- Warn: no topLevel permission defined: .github/workflows/examples.yml:1
- Warn: no topLevel permission defined: .github/workflows/npm_downloads.yml:1
- Warn: no topLevel permission defined: .github/workflows/productionize.yml:1
- Warn: no topLevel permission defined: .github/workflows/publish.yml:1
- Warn: no topLevel permission defined: .github/workflows/test.yml:1
- Warn: no topLevel permission defined: .github/workflows/test_bundles.yml:1
- Warn: no topLevel permission defined: .github/workflows/test_coverage.yml:1
- Warn: no topLevel permission defined: .github/workflows/test_install.yml:1
- Warn: no topLevel permission defined: .github/workflows/test_published_package.yml:1
- Info: no jobLevel write permissions found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Score
4.3
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More