From 48a80456605aced4ea61fed8db11d81e9f6abc7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=A5=E6=B5=A9?= Date: Sun, 13 Oct 2024 16:55:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=96=87=E4=BB=B6=E5=B9=B6?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=AD=A3=E5=88=99=E8=A1=A8=E8=BE=BE=E5=BC=8F?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test-regex/file.txt | 3 +++ test-regex/run.mjs | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 test-regex/file.txt create mode 100644 test-regex/run.mjs diff --git a/test-regex/file.txt b/test-regex/file.txt new file mode 100644 index 0000000..4216823 --- /dev/null +++ b/test-regex/file.txt @@ -0,0 +1,3 @@ +before line +somethins# renovate: datasource=docker depName=DepName:latest@sha256:f41be3dcaa8fbe256e8d084c2d938001311db05c26eb84936451f4a82e2af615 +after line \ No newline at end of file diff --git a/test-regex/run.mjs b/test-regex/run.mjs new file mode 100644 index 0000000..75d0f6e --- /dev/null +++ b/test-regex/run.mjs @@ -0,0 +1,20 @@ +import * as path from "node:path"; +import { fileURLToPath } from "node:url"; +import fs from "node:fs"; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); + + +function extractMatchResult(regex, text) { + const pattern = new RegExp(regex); + const match = text.match(pattern); + console.log("match", match); + return match; +} + +const filecontent = fs.readFileSync(path.join(__dirname, "file.txt"), "utf8"); + +(() => { + const regex = "# renovate: datasource=(?\\S+) depName=(?\\S+):(?\\S+)@(?\\S+)"; + extractMatchResult(regex, filecontent); +})();