/const meta = ([\s\S]*?) satisfies (Meta(.+));/g
const meta: $2 = $1;
根据某些系统(例如 regex101.com),用 替换似乎就是我想要的。
但它在 VSCode 中不起作用。
要搜索的示例文本:
const meta = {
args: {
description: 'This is a test alert for interaction testing.',
},
argTypes: {
hasBackground: {
control: 'boolean',
},
variant: {
control: { type: 'select' },
},
},
component: Alert,
parameters: {
design: {
type: 'figma',
},
},
title: 'Component/Alert',
} satisfies Meta<typeof Alert>;
const meta = {
argTypes: {
number: {
if: { arg: 'size', eq: 'lg' },
},
size: {
options: ['sm', 'md', 'lg'],
},
variant: {
control: 'select',
},
},
component: Badge,
parameters: {
design: {
type: 'figma',
},
},
title: 'Component/Badge',
} satisfies Meta<typeof Badge>;
替换成功:
如何在 VSC 中完成我所有项目文件中的正则表达式查找和替换?
或者我应该使用其他工具吗?
VSCode 中的正则表达式多行搜索
VSCode 仅在包含文字时才在搜索中包含换行符
\n
(请参阅进一步阅读部分),因此这里的一个潜在解决方案是添加\n
到字符集(在内[\S\s]
)“查找”模式应更新为:
正如原始问题所建议的那样,替换模式很好。
进一步阅读
Visual Studio Code 中的多行正则表达式搜索 https://code.visualstudio.com/updates/v1_29#_multiline-search