Use named group

This commit is contained in:
Andras Schmelczer 2025-11-28 21:23:55 +00:00
parent e53482ced8
commit 7a95d9f0a8

View file

@ -9,7 +9,7 @@ import { isBinary } from "../utils/is-binary";
import type { ServerConfig } from "../services/server-config";
export class FileOperations {
private static readonly PARENTHESES_REGEX = / \((\d+)\)$/;
private static readonly PARENTHESES_REGEX = / \((?<count>\d+)\)$/;
private readonly fs: SafeFileSystemOperations;
public constructor(
@ -251,7 +251,8 @@ export class FileOperations {
: "";
let stem = extension ? nameParts.slice(0, -1).join(".") : fileName;
let currentCount = Number.parseInt(
FileOperations.PARENTHESES_REGEX.exec(stem)?.[1] ?? "0"
FileOperations.PARENTHESES_REGEX.exec(stem)?.groups?.["count"] ??
"0"
);
stem = stem.replace(FileOperations.PARENTHESES_REGEX, "");