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

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -