javascript - Grabbing only the YAML text from a file in JS -
suppose have file has random text mixed yaml text. yaml text between --- , ....
goal: goal take string (taken such file):
--- some: "yaml" some: "more yaml" ... random text that's not yaml. --- more: "yaml" ... and output string contains only yaml parts (including --- , ... delimiters):
--- some: "yaml" some: "more yaml" ... --- more: "yaml" ... how 1 this?
this can done string.prototype.match + array.prototype.join:
function extractyaml(string) { return string.match(/(---(.|\n)*?\.\.\.\n)/g).join(''); }
Comments
Post a Comment