{"id":15642868,"url":"https://github.com/trusktr/regexr","last_synced_at":"2025-10-18T18:27:10.550Z","repository":{"id":34175412,"uuid":"38023877","full_name":"trusktr/regexr","owner":"trusktr","description":"Easily compose regular expressions without the need for double-escaping inside strings.","archived":false,"fork":false,"pushed_at":"2024-02-21T02:15:31.000Z","size":391,"stargazers_count":64,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-06T23:42:15.010Z","etag":null,"topics":["es6","hand-picked-regexes","javascript","regex","regex-engine","regex-util","regexes","regexp","regexr","regular-expression","template-string"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/trusktr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-06-25T02:42:28.000Z","updated_at":"2025-02-11T18:53:06.000Z","dependencies_parsed_at":"2024-06-18T22:39:51.345Z","dependency_job_id":"ccc0e383-c961-429a-bb34-0792441adf2c","html_url":"https://github.com/trusktr/regexr","commit_stats":{"total_commits":58,"total_committers":2,"mean_commits":29.0,"dds":0.06896551724137934,"last_synced_commit":"f6db05df0c81ca2bf418b2fbcfc5d8da8274a300"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"purl":"pkg:github/trusktr/regexr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trusktr%2Fregexr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trusktr%2Fregexr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trusktr%2Fregexr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trusktr%2Fregexr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trusktr","download_url":"https://codeload.github.com/trusktr/regexr/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trusktr%2Fregexr/sbom","scorecard":{"id":899981,"data":{"date":"2025-08-11","repo":{"name":"github.com/trusktr/regexr","commit":"f6db05df0c81ca2bf418b2fbcfc5d8da8274a300"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":1.7,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'main'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Vulnerabilities","score":0,"reason":"17 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-28mc-g557-92m7","Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-4gmj-3p3h-gm8h","Warn: Project is vulnerable to: GHSA-78xj-cgh5-2h22","Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp","Warn: Project is vulnerable to: GHSA-593f-38f6-jp5m","Warn: Project is vulnerable to: GHSA-x2rg-q646-7m2v","Warn: Project is vulnerable to: GHSA-jgmv-j7ww-jx2x","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55","Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j","Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm","Warn: Project is vulnerable to: GHSA-pq67-2wwv-3xjx","Warn: Project is vulnerable to: GHSA-8cj5-5rvv-wf4v","Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-24T15:12:35.186Z","repository_id":34175412,"created_at":"2025-08-24T15:12:35.186Z","updated_at":"2025-08-24T15:12:35.186Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279007311,"owners_count":26084280,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["es6","hand-picked-regexes","javascript","regex","regex-engine","regex-util","regexes","regexp","regexr","regular-expression","template-string"],"created_at":"2024-10-03T11:57:55.422Z","updated_at":"2025-10-18T18:27:10.517Z","avatar_url":"https://github.com/trusktr.png","language":"TypeScript","readme":"# regexr\n\nEasily compose regular expressions. Doing this with plain strings would otherwise be\ntedious and error prone due to having to double-escape backslashes.\n\n#### [`npm install regexr`](https://npmjs.com/regexr)\n\nBasic example:\n\n```js\nimport r from 'regexr'\n\nconst int = /\\d+/\nconst USD = r`\\$${int}(\\.${int})?` // f.e. $3.45 or $5\n```\n\n(Note that `int` is an instance of `RegExp` and can be composed into the\ntemplate string, and the resulting `USD` is also a `RegExp`)\n\nRegexr provides an ES6 template tag function that makes it easy to compose\n`RegExp`s using template strings without double-escaped hell.\n\nIn ES5 and below, we may try to compose the regular expressions like so:\n\n```js\nconst int = '\\d+'\nlet USD = new RegExp('\\$'+int+'(\\.'+int+')?`) // this won't work!\n```\n\nbut if you're experienced enough, you'd know that if you want to compose\nregular expressions using ES5 strings you have to escape the escape:\n\n```js\nconst int = '\\\\d+'\nconst USD = new RegExp('\\\\$'+int+'(\\\\.'+int+')?`) // correct!\n```\n\nImagine making more complex regexes! For example, compare the following two\nexamples achieving the same thing in ES5 and ES6 respectively:\n\n```js\n// in ES5, the double escaping can get confusing:\nconst spaceRegex = '\\\\s*'\nconst finalRegex = new RegExp('\\\\(' + spaceRegex + '\\\\/\\\\[\\\\\\\\\\\\d+\\\\]\\\\)*$', 'g')\nconsole.log(!!'( /[\\\\12358])'.match(finalRegex)) // true\n```\n\n```js\n// in ES6, we don't have to double escape, thanks to regexr:\nimport r from 'regexr'\n\nconst spaceRegex = r`\\s*`\nconst finalRegex = r`/\\(${spaceRegex}\\/\\[\\\\\\d+\\]\\)*$/g`\nconsole.log(!!'( /[\\\\12358])'.match(finalRegex)) // true\n```\n\n## API\n\n#### ` r`` ` template tag function\n\n```js\nimport r from 'regexr'\n// or\nconst r = require('regexr').default\n```\n\n` r`` ` is a template tag function that converts the given string into a\nRegExp without requiring double escaping. Instances of `RegExp` can be mixed\ninto the string, and will be composed into the final `RegExp`.\n\nExample:\n\n```js\nconst digit = /\\d/\nconst integer = r`/${digit}+/`\nconst number = r`/${integer}|${digit}*\\.${integer}|${integer}\\.${digit}*/` // f.e. 4.2, .5, 5.\n```\n\n### Helpers\n\n#### `escape` (alias `e`)\n\nEscape (add backslashes to) a string for so that we can match all symbols in the\nstring literally when the string is used as a regex.\n\nIn the following example, we want to find occurrences of the string `\"value: $5.00\"` in some input, so we need to escape the `money` string so that the\ndollar symbol (`$`) doesn't represent end-of-line and the period (`.`) doesn't\nmean any character:\n\n```js\nimport {e} from 'regexr'\n\nconst money = '$5.00'\nconst fiveDollarRegex = r`value: ${e(money)}`\n\nconsole.log(fiveDollarRegex) // /value: \\$5\\.00/\nconsole.log('value: $5.00'.match(fiveDollarRegex)) // true\nconsole.log('value: $5.50'.match(fiveDollarRegex)) // false\n```\n\n### Hand-picked Regexes\n\nRegexr comes with some pre-selected regular expressions. For example, we can\nrewrite the first example:\n\n```js\nimport r from 'regexr'\nimport * as regs from 'regexr/regexes'\n\nconst USD = r`\\$${regs.integer}(\\.${regs.integer})?` // f.e. $3.45 or $5\n```\n\nwhere `regs.integer` is an instance of `RegExp`.\n\n**_NOTE! Some of the following RegExps require to be wrapped in `()` when they\nare being composed into bigger RegExps. These will be noted below._**\n\n#### `regs.identifier`\n\nMatches a valid JavaScript identifier. See\n[this](http://stackoverflow.com/questions/2008279/validate-a-javascript-function-name/9392578#9392578)\nfor details.\n\n**_Requires wrapping in `()` when being composed._**\n\nFor example, to match a the beginning of a JS variable declaration, you could\nwrite:\n\n```js\nimport * as regs from 'regexr/regexes'\nconst variableDeclaration = r`(const|let|var)\\s+(${regs.identifier})\\s*=`\n!!'const foo  ='.match(variableDeclaration) // true\n!!'const foo bar ='.match(variableDeclaration) // false\n```\n\n#### `regs.digit`\n\nMatches a single numerical digit (0-9).\n\nExample:\n\n```js\nimport * as regs from 'regexr/regexes'\n!!' 8 '.match(r` ${regs.digit} `) // true\n!!' 25 '.match(r` ${regs.digit} `) // false\n```\n\n#### `regs.integer`\n\nMatches 1 or more digits.\n\nExample:\n\n```js\nimport * as regs from 'regexr/regexes'\n!!' 432 '.match(r` ${regs.integer} `) // true\n```\n\n#### `regs.number`\n\nMatches a JavaScript Number.\n\nExample:\n\n```js\nimport * as regs from 'regexr/regexes'\n!!'3'.match(regs.number) // true\n!!'432'.match(regs.number) // true\n!!'4.2'.match(regs.number) // true\n!!'5.'.match(regs.number) // true\n!!'.34'.match(regs.number) // true\n```\n\n#### `regs.identifierList`\n\nMatches a comma separated list of legal JavaScript identifiers.\n\nExample:\n\n```js\nimport * as regs from 'regexr/regexes'\nconst identifiersInsideParens = r`\\(${regs.identifierList}\\)`\n\n!!'(foo,  bar,baz)'.match(identifiersInsideParens) // true\n!!'(foo, ,bar, baz)'.match(identifiersInsideParens) // false\n```\n\n#### `regs.functionHeader`\n\nMatches a JavaScript function header.\n\nExample:\n\n```js\nimport * as regs from 'regexr/regexes'\nconst identifiersInsideParens = r`\\(${regs.identifierList}\\)`\n\n!!'function() {'.match(regs.functionHeader) // true\n!!'function asdf() {'.match(regs.functionHeader) // true\n!!'function (asdf ) {'.match(regs.functionHeader) // true\n!!'function asdf (asdf ) {'.match(regs.functionHeader) // true\n!!'function asdf(asdf  , asdf, ) {'.match(regs.functionHeader) // true\n!!'function (asdf, asdf, asdfa asdf ) {'.match(regs.functionHeader) // false\n!!'function asdf (asdf, asdf, asdfa asdf ) {'.match(regs.functionHeader) // false\n!!'function asdf asdf (asdf, asdf, asdfa ) {'.match(regs.functionHeader) // false\n!!'function asdf asdf (, asdf, asdf,) {'.match(regs.functionHeader) // false\n!!'function (asdf asdf) {'.match(regs.functionHeader) // false\n!!'function (asdf,,) {'.match(regs.functionHeader) // false\n```\n","funding_links":[],"categories":["Libraries"],"sub_categories":["Regular Expressions"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrusktr%2Fregexr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrusktr%2Fregexr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrusktr%2Fregexr/lists"}