也許這是你想先更改文件內容到數組像這樣的內容:
var fs = require('fs')
var fileContent = fs.readFileSync("peking.txt", { encoding: 'utf8' });
var splitSimpleSwagger=fileContent.split(/@SimpleSwagger/).filter(function(token){
return token != ""
})
console.log(splitSimpleSwagger)
//this will return 2 array which is the word above string @SimpleSwagger and the word
//after @SimpleSwagger like this:
//[ 'var fileContent = fs.readFileSync(file, { encoding: \'utf8\' });\nvar
//regexResults = fileContent.m
//atch(jsDocRegex);\n\n /**\n * ',
//'\n * Model:\n * name: Car\n */' ]
//so if you want to get only this '\n * Model:\n * name: Car\n */' just do this:
console.log(splitSimpleSwagger[1])
//then you will get the contain of the comment after word '@SimpleSwagger' which is
//'\n * Model:\n * name: Car\n */'
//and if you want to clean that up just do this:
console.log(splitSimpleSwagger[1].split("*").join("").replace("/",""))
//it will return
型號:
名稱:汽車