-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathdebug_regex.js
More file actions
29 lines (25 loc) · 971 Bytes
/
debug_regex.js
File metadata and controls
29 lines (25 loc) · 971 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const path = "C:\\Users\\99523\\Downloads\\GIF 2025-7-18 17-29-00.gif";
// 注意:在 JS 字符串中,反斜杠本身需要转义。用户输入的路径包含反斜杠。
const markdown = ``;
const regex = /!\[([^\]]*)\]\(([^)]+)\)/g;
console.log("Testing Markdown String:", markdown);
const replaced = markdown.replace(regex, (match, alt, src) => {
console.log("Match found!");
console.log("Alt:", alt);
console.log("Src:", src);
if (src.includes(" ")) {
const newSrc = src.replace(/ /g, "%20");
console.log("Replacing with:", newSrc);
return ``;
}
return match;
});
console.log("Result:", replaced);
// 测试 Input Rule 正则
const inputRuleRegex = /!\[([^\]]*)\]\(([^)]+)\)$/;
console.log("Testing Input Rule match...");
const match = inputRuleRegex.exec(markdown);
console.log("Input Rule Match:", match ? "YES" : "NO");
if (match) {
console.log("Captured Src:", match[2]);
}