Repository: TypeScript
Issue: Regular Expression finds
Labels: Discussion

### Acknowledgement

- [X] I acknowledge that issues using this template may be closed without further explanation at the maintainer's discretion.

### Comment

Note: I eventually gave up on capturing "Not available unless target is ESXXXX" errors since they're not really interesting to look at

Via #58275

[This character cannot be escaped in a regular expression.](https://github.com/AbdullahAlfaraj/Auto-Photoshop-StableDiffusion-Plugin/blob/6f6d4907adf0b6a6e562d084238f02ed6b7503c1/utility/html_manip.js#L461)
```ts
const image_path_escape = image_path.replace(/\o/g, '/o') //escape string "\o" in "\output"
```

[Named capturing groups are only available when targeting 'ES2018' or later](https://github.com/adobe/react-spectrum/blob/1d70153c126e84fa7550ff63e3e48fd92b095ca8/packages/@internationalized/date/src/string.ts#L26)
```ts
/^((?<negative>-)|\+)?P((?<years>\d*)Y)?((?<months>\d*)M)?((?<weeks>\d*)W)?((?<days>\d*)D)?((?<time>T)((?<hours>\d*[.,]?\d{1,9})H)?((?<minutes>\d*[.,]?\d{1,9})M)?((?<seconds>\d*[.,]?\d{1,9})S)?)?$/
```

[Named capturing groups are only available when targeting 'ES2018' or later.](https://github.com/angular/angularfire/blob/73b40da11f7f56884c86da9cbe1123f3d00bc866/src/schematics/update/v7/index.ts#L7)
```ts
const IMPORT_REGEX = /(?<key>import|export)\s+(?:(?<alias>[\w,{}\s*]+)\s+from)?\s*(?:(?<quote>["'])?(?<ref>[@\w\s\\/.-]+)\3?)\s*(?<term>[;\n])/g
```

[Named capturing groups are only available when targeting 'ES2018' or later](https://github.com/ariakit/ariakit/blob/c18f793aed1af7235b8b2a5ed2b3d6db3501dff6/website/build-pages/reference-utils.js#L181)
```ts
const match = text.match(/^(?<description>(.|\n)*)```(?<language>[^\n]+)\n(?<code>(.|\n)+)\n```$/m);
```

[This regular expression flag is only available when targeting 'es2018' or later](https://github.com/backstage/backstage/blob/d26e5a5d45ee34d3633df8f878477ccd22d947ae/microsite/docusaurus.config.js#L74)
```ts
return fileContent.replace(/<!--.*?-->/gs, '');
```

[This character cannot be escaped in a regular expression](https://github.com/bitwarden/clients/blob/91f1d9fb86142805d0774182c3ee6234e13946e3/apps/web/src/connectors/common-webauthn.ts#L32)
```ts
const fixedId = listItem.id.replace(/\_/g, "/").replace(/\-/g, "+");
```

[Named capturing groups are only available when targeting 'ES2018' or later](https://github.com/BuilderIO/mitosis/blob/ed923e4a07dd80579083cf9a1c4d7158028d2b25/packages/core/src/helpers/component-file-extensions.ts#L48)
```ts
const INPUT_EXTENSION_IMPORT_REGEX = /\.(svelte|(lite(\.tsx|\.jsx)?))(?<quote>['"])/g;
```

[Octal escape sequences are not allowed. Use the syntax '\x04'](https://github.com/BuilderIO/mitosis/blob/ed923e4a07dd80579083cf9a1c4d7158028d2b25/packages/core/src/helpers/get-prop-functions.ts#L4)
```ts
const propsRegex = /props\s*\.\s*([a-zA-Z0-9_\4]+)\(/;
```

[Named capturing groups are only available when targeting 'ES2018' or later](https://github.com/caprover/caprover/blob/1d6240811ba6d8e346aeb3303b690b483b12b6c1/src/utils/GitHelper.ts#L16)
```ts
private static SSH_PATH_RE = new RegExp(
    [
        /^\s*/,
        /(?:(?<proto>[a-z]+):\/\/)?/,
        /(?:(?<user>[a-z_][a-z0-9_-]+)@)?/,
        /(?<domain>[^\s\/\?#:]+)/,
        /(?::(?<port>[0-9]{1,5}))?/,
        /(?:[\/:](?<owner>[^\s\/\?#:]+))?/,
        /(?:[\/:](?<repo>(?:[^\s\?#:.]|\.(?!git\/?\s*$))+))/,
        /(?:.git)?\/?\s*$/,
    ]
```

[Named capturing groups are only available when targeting 'ES2018' or later](https://github.com/Chocobozzz/PeerTube/blob/8e30e1f5fd64077e6d379425a3c0a61103051aa0/client/e2e/src/utils/email.ts#L4)
```ts
const regexp = /\[(?<link>http:\/\/[^\]]+)\]/g
```

[A character class range must not be bounded by another character class](https://github.com/compiler-explorer/compiler-explorer/blob/cd75b4af4d43f03689d7791b1ec438062f6282fa/lib/parsers/asm-parser.ts#L138)
```ts
this.relocDataSymNameRe = /^(?<symname>[^\d-+][\w.]*)?\s*(?<addend_or_value>.*)$/;

filepath.replace(/^C:\/Users\/[\w\d-.]*\/AppData\/Local\/Temp\/compiler-explorer-compiler[\w\d-.]*\//, '/app/')

const ATFILELINE_RE = /\s*at ([\w-/.]+):(\d+)/;

const selectedPassRe = /[0-9]*(i|t|r)\.([\w-_]*)/;
```

[Octal escape sequences are not allowed. Use the syntax '\x02'.](https://github.com/curlconverter/curlconverter/blob/cf2aab4ce918792a2ae8ad9d689f1c4fac74becb/src/generators/wget.ts#L88)
```ts
const shellChars = /[\002-\011\013-\032\\#?`(){}[\]^*<=>~|; "!$&'\202-\377]/;
```

[This character cannot be escaped in a regular expression.](https://github.com/desktop/desktop/blob/873520111b0311116c4de8b4e8281629b226cc44/app/src/lib/markdown-filters/commit-mention-link-filter.ts#L40)
```ts
private readonly nameWithOwner = /(?<owner>-?[a-z0-9][a-z0-9\-\_]*)\/(?<name>(?:\w|\.|\-)+)/;

const isURlCustomFormat = /\.[a-z]+\z/.test(anchor.href);
```

[Octal escape sequences are not allowed. Use the syntax '\x02'](https://github.com/dotansimha/graphql-code-generator/blob/1ac08cca7a25a47b0488601c2a733294065a08c3/packages/graphql-codegen-cli/tests/cli-flags.spec.ts#L7)
```ts
const regexp = /([^\s'"]+(['"])([^\2]*?)\2)|[^\s'"]+|(['"])([^\4]*?)\4/gi;
```

[A character class range must not be bounded by another character class](https://github.com/facebook/lexical/blob/8fda1b4da933dbe46ba7d01478473a8b46bd4aa7/packages/lexical-playground/src/utils/url.ts#L32)
```ts
// Source: https://stackoverflow.com/a/8234912/2013580
const urlRegExp = new RegExp(
  /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%/.\w-_]*)?\??(?:[-+=&;%@.\w_]*)#?(?:[\w]*))?)/,
);
```

[This regular expression flag is only available when targeting 'es2022' or later](https://github.com/foambubble/foam/blob/db7eb9775f0a94e99ea73e17b64e1360a831e99e/packages/foam-vscode/src/features/tag-completion.ts#L9)
```ts
// this regex is different from HASHTAG_REGEX in that it does not look for a
// #+character. It uses a negative look-ahead for `# `
const HASH_REGEX =
  /(?<=^|\s)#(?![ \t#])([0-9]*[\p{L}\p{Emoji_Presentation}\p{N}/_-]*)/dgu;
```

[This regular expression flag is only available when targeting 'es2018' or later](https://github.com/formatjs/formatjs/blob/c063f7bc4530af7ec6c5b68000887a3f55948f6e/packages/icu-messageformat-parser/printer.ts#L71)
```ts
return message.replace(/([{}](?:.*[{}])?)/su, `'$1'`)
```

[This regular expression flag is only available when targeting 'es6' or later](https://github.com/formatjs/formatjs/blob/c063f7bc4530af7ec6c5b68000887a3f55948f6e/packages/icu-messageformat-parser/printer.ts#L71)
```ts
return message.replace(/([{}](?:.*[{}])?)/su, `'$1'`)
```

[Octal escape sequences are not allowed. Use the syntax '\x00'](https://github.com/gitkraken/vscode-gitlens/blob/c3a5cf55d92ab4ca090f6f7d047be50414daa824/src/plus/integrations/providers/github/githubGitProvider.ts#L119)
```ts
// Since negative lookbehind isn't supported in all browsers, this leaves out the negative lookbehind condition `(?<!\.lock)` to ensure the branch name doesn't end with `.lock`
const validBranchOrTagRegex = /^[^/](?!.*\/\.)(?!.*\.\.)(?!.*\/\/)(?!.*@\{)[^\000-\037\177 ~^:?*[\\]+[^./]$/;

// Since negative lookbehind isn't supported in all browsers, leave out the negative lookbehind condition `(?<!\.lock)` to ensure the branch name doesn't end with `.lock`
const refRegexShared = /\b((?!.*\/\.)(?!.*\.\.)(?!.*\/\/)(?!.*@\{)[^\000-\037\177 ,~^:?*[\\]+[^ ./])\b/gi;
```

[This regular expression flag is only available when targeting 'es2018' or later](https://github.com/hexojs/hexo/blob/093dc2d1c92dd7fdea74bb1ccc2208556316e2a6/lib/hexo/post.ts#L72)
```ts
if (!/(\{\{.+?\}\})|(\{#.+?#\})|(\{%.+?%\})/s.test(str)) {
```

[A character class range must not be bounded by another character class](https://github.com/hexojs/hexo/blob/093dc2d1c92dd7fdea74bb1ccc2208556316e2a6/lib/plugins/tag/img.ts#L4)
```ts
const rUrl = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%/.\w-_]*)?\??(?:[-+=&;%@.\w_]*)#?(?:[.!/\\w]*))?)/;
```

[This character cannot be escaped in a regular expression](https://github.com/honojs/hono/blob/9f9a41cc08f131cd47480cb3e9982939d1db1909/src/validator/validator.test.ts#L155)
```ts
    expect(data['message']).toMatch(
      /Malformed FormData request. \_*Response.formData: Could not parse content as FormData./
    )
```

[This regular expression flag is only available when targeting 'es6' or later](https://github.com/infinitered/ignite/blob/4795ee1d4eacebf6c0f8410401e49c888b65ec6b/src/tools/validations.ts#L82)
```ts
const validBundleID = /^([a-zA-Z]([a-zA-Z0-9_])*\.)+[a-zA-Z]([a-zA-Z0-9_])*$/u
```

[There is nothing available for repetition](https://github.com/javascript-obfuscator/javascript-obfuscator/blob/1000402f10f61bd367cd971d55f0f832d940d60e/test/functional-tests/node-transformers/converting-transformers/numbers-to-numerical-expressions-transformer/NumbersToNumericalExpressionsTransformer.spec.ts#L239)
```ts
const regExp: RegExp = /const foo *= *{0x1: *'bar'};/;
```

[ '}' expected]()
```ts
/tag`foo *\${0x1 *\+ *0x1} *bar`;/
```

[A character class range must not be bounded by another character class](https://github.com/jhipster/generator-jhipster/blob/dfc53785c811a763d358e964c03c34670b974f2d/generators/project-name/support/name-resolver.ts#L40)
```ts
if (!/^([\w-.]*)$/.test(name)) {
```

[A character class range must not be bounded by another character class.](https://github.com/jupyterlab/jupyterlab/blob/8819549495cd11470b4db7464d1d59c53cfce787/packages/coreutils/src/text.ts#L86)
```ts
return str.replace(/^(\w)|[\s-_:]+(\w)/g, function (match, p1, p2) {
```

[A character class range must not be bounded by another character class](https://github.com/microsoft/azuredatastudio/blob/f1d4c06d0517e3386e4592c71fe6cc222c2916dc/extensions/notebook/src/dialog/remoteBookDialog.ts#L13)
```ts
const urlGithubRE = /^(?:https:\/\/(?:github\.com|api\.github\.com\/repos)|(?:\/)?(?:\/)?repos)([\w-.?!=&%*+:@\/]*)/g;
```

[This character cannot be escaped in a regular expression.](https://github.com/microsoft/vscode/blob/5ae5a741bdb676abb667fd4896dc2a40e313db3a/src/vs/base/browser/dom.ts#L2222)
```ts
const H_REGEX = /(?<tag>[\w\-]+)?(?:#(?<id>[\w\-]+))?(?<class>(?:\.(?:[\w\-]+))*)(?:@(?<name>(?:[\w\_])+))?/;
```

[This regular expression flag is only available when targeting 'es2022' or later.](https://github.com/microsoft/vscode/blob/5ae5a741bdb676abb667fd4896dc2a40e313db3a/src/vs/editor/common/services/findSectionHeaders.ts#L39)
```ts
const markRegex = /\bMARK:\s*(.*)$/d;
```

[Octal escape sequences are not allowed. Use the syntax '\x09'.](https://github.com/microsoft/vscode/blob/5ae5a741bdb676abb667fd4896dc2a40e313db3a/src/vs/editor/common/services/getIconClasses.ts#L122)
```ts
function cssEscape(str: string): string {
	return str.replace(/[\11\12\14\15\40]/g, '/'); // HTML class names can not contain certain whitespace characters, use / instead, which doesn't exist in file names.
}
```

[A character class range must not be bounded by another character class.](https://github.com/microsoft/vscode/blob/5ae5a741bdb676abb667fd4896dc2a40e313db3a/src/vs/platform/telemetry/common/telemetryUtils.ts#L294)
```ts
const fileRegex = /(file:\/\/)?([a-zA-Z]:(\\\\|\\|\/)|(\\\\|\\|\/))?([\w-\._]+(\\\\|\\|\/))+[\w-\._]*/g;
```

[A character class range must not be bounded by another character class.](https://github.com/misskey-dev/misskey/blob/f9aed8f2bf994902386878d1212912caa3a57b0d/packages/backend/src/core/activitypub/models/ApPersonService.ts#L157)
```ts
/^\w([\w-.]*\w)?$/.test(x.preferredUsername)
```

[Named capturing groups are only available when targeting 'ES2018' or later](https://github.com/mui/material-ui/blob/c435f65536a0b84ee86140790761daa97f7ec8cf/packages/api-docs-builder/ApiBuilders/ComponentApiBuilder.ts#L554)
```ts
const deprecation = (propDescriptor.description || '').match(/@deprecated(\s+(?<info>.*))?/);
```

[A character class range must not be bounded by another character class.](https://github.com/neoclide/coc.nvim/blob/77ae2d43c16e69746a3e097d8d2f960a8d962593/src/completion/util.ts#L97)
```ts
let isText = /^[\w-\s.,\t\n]+$/.test(detail)
```

[This character cannot be escaped in a regular expression](https://github.com/portainer/portainer/blob/5f89d70fd81e1f59e8430d6d50fde2d4a9483d21/app/docker/helpers/imageHelper.js#L14)
```ts
return tag.match(/^(?![\.\-])([a-zA-Z0-9\_\.\-])+$/g);
```

[A character class range must not be bounded by another character class](https://github.com/reactjs/react.dev/blob/37a8d646bfab5b11a583e963f3bc0429270c0b36/src/components/MDX/ErrorDecoder.tsx#L26)
```ts
const urlRegex = () =>
  /((?:https?(?::\/\/))(?:www\.)?(?:[a-zA-Z\d-_.]+(?:(?:\.|@)[a-zA-Z\d]{2,})|localhost)(?:(?:[-a-zA-Z\d:%_+.~#!?&//=@]*)(?:[,](?![\s]))*)*)/g;
```

[A character class range must not be bounded by another character class](https://github.com/Redocly/redoc/blob/3f3f9551ee36f8743a65d774f5212a34dea1affc/src/utils/openapi.ts#L592)
```ts
export function expandDefaultServerVariables(url: string, variables: object = {}) {
  return url.replace(
    /(?:{)([\w-.]+)(?:})/g,
    (match, name) => (variables[name] && variables[name].default) || match,
  );
}
```


**dozens of these in this file**, see https://github.com/microsoft/TypeScript/issues/58275#issuecomment-2068174097

[A decimal escape must refer to an existent capturing group. There are only 1 capturing groups in this regular expression](https://github.com/resend/react-email/blob/6ff630a0c254f2172b53e029c6130a41ebcc4664/packages/code-block/src/prism.ts#L1482)
```ts
/([^a-zA-Z0-9\s{(\[<])(?:(?!\2)[^\\]|\\[\s\S])*\2(?:(?!\2)[^\\]|\\[\s\S])*\2/
```

[A character class range must not be bounded by another character class](https://github.com/subquery/subql/blob/4f47a0a76a90f4cd8b4e927f6965ac2835756c2a/packages/common/src/project/readers/reader.ts#L17)
```ts
    // eslint-disable-next-line @typescript-eslint/prefer-regexp-exec
    const githubMatch = location.match(/https:\/\/github.com\/([\w-_]+\/[\w-_]+)/i);
```


[Unicode property value expressions are only available when the Unicode (u) flag or the Unicode Sets (v) flag is set](https://github.com/vendure-ecommerce/vendure/blob/9c1cb1662e899c62d93f8741f9476f415c721998/packages/admin-ui/src/lib/catalog/src/components/collection-detail/collection-detail.component.ts#L64)
```ts
    slug: ['', unicodePatternValidator(/^[\p{Letter}0-9._-]+$/)],
```

[A character class range must not be bounded by another character class](https://github.com/vuejs/vetur/blob/96aaa707f8ca629f0883c57a47adb0e58995936d/server/src/modes/style/stylus/index.ts#L147)
```ts
export const wordPattern = /(#?-?\d*\.\d\w*%?)|([$@#!.:]?[\w-?]+%?)|[$@#!.]/g;

return stream.advanceIfRegExp(/^[_:\w][_:\w-.\d]*/).toLowerCase();
```