mirror of
https://github.com/yanhao98/renovate-example.git
synced 2025-07-13 04:10:49 +08:00
新增文件并实现正则表达式匹配功能
This commit is contained in:
3
test-regex/file.txt
Normal file
3
test-regex/file.txt
Normal file
@ -0,0 +1,3 @@
|
||||
before line
|
||||
somethins# renovate: datasource=docker depName=DepName:latest@sha256:f41be3dcaa8fbe256e8d084c2d938001311db05c26eb84936451f4a82e2af615
|
||||
after line
|
20
test-regex/run.mjs
Normal file
20
test-regex/run.mjs
Normal file
@ -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=(?<datasource>\\S+) depName=(?<depName>\\S+):(?<currentValue>\\S+)@(?<currentDigest>\\S+)";
|
||||
extractMatchResult(regex, filecontent);
|
||||
})();
|
Reference in New Issue
Block a user