两个字符串之间的Nodejs readFileSync regex标记

问题描述 投票:0回答:1

我正在尝试借助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进行任何字符串操作。

指导我在哪里做错。

javascript node.js regex fs string-matching
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.