如何在JavaScript中获取匹配的正则表达式内容?

如何在JavaScript中获取匹配的正则表达式内容?,javascript,Javascript,考虑到字符串, #[pill(hello.0.LastName)] 如何获取hello.0.LastName 以下是正则表达式模式: const dataPillRegex=/\[hello\(.*?)\]/g这里有一个解决方案,output是一个数组,其中包含各种不同的信息,但您需要的唯一信息是output[1]。尽管如此,我仍然建议将整个输出记录到控制台,以便您可以查看其中的内容 const input=“#[pill(hello.0.LastName)]”; 输出=输入。匹配(/#\[pi

考虑到字符串, #[pill(hello.0.LastName)]

如何获取
hello.0.LastName

以下是正则表达式模式:
const dataPillRegex=/\[hello\(.*?)\]/g

这里有一个解决方案,
output
是一个数组,其中包含各种不同的信息,但您需要的唯一信息是
output[1]
。尽管如此,我仍然建议将整个
输出记录到控制台,以便您可以查看其中的内容

const input=“#[pill(hello.0.LastName)]”;
输出=输入。匹配(/#\[pill\(.+)\)\]/);
console.log(输出[1]);
输出:

hello.0.LastName
hello.0.LastName
如果不需要多余的数据,还可以在正则表达式字符串的末尾添加
g

const input=“#[pill(hello.0.LastName)]”;
输出=输入.match(/\[pill\(.+)\)\]/g);
console.log(输出[0]);
输出:

hello.0.LastName
hello.0.LastName