我正在尝试借助nodejs
fs.readFileSync()
函数将文件内容提取为这样的字符串:
let fileData = fs.readFileSync('./path, 'utf8');
此后,我想通过regex
获得两个字符串之间的内容:
我有类似这样的字符串:
<route-meta>
{
"requiresAuth": true
}
</route-meta>
<template>
</template>
<script>
export default {
name: "check"
}
</script>
<style scoped>
</style>
我需要在<route-meta>
和</route-meta>
之间找到文本/字符串,所以结果应该是:
{
"requiresAuth": true
}
我尝试使用fileData.match(/<route-meta>(.*?)<\/route-meta>/);
进行此操作,但不知何故,它给了我null
结果
我遵循此示例:Regex match text between tags
[我也尝试检查fileData.replace('route-meta', '');
,但仍然没有得到想要的结果,我的意思是我无法使用fileData
进行任何字符串操作。
指导我在哪里做错。