• Using regular expressions to extract content between a comma and end of line

    So, more regex, this time extracting the final value in a row of a csv file. This is one step in a task to convert a csv file into a tsv file This step needs to cope with handling prior columns in the row containing text with comma characters.

    // final column in a row capture
    const regex = /^.*,\s*(.*)$/g;

    January 14, 2018 - 1 minute read - regex javascript
  • Using regular expressions to remove frontmatter

    I recently found the need to strip frontmatter from source markdown files. After far too long playing around with regex101.com I finally came up with the following expression to work the magic.

    // frontmatter removal
    const regex = /^---(.|\n)*?---\n/;

    Frontmatter is a code block found at the beginning of a file and is used to manage meta data for that page of content. I’m working with frontmatter in YAML format so the code block is enclosed with — characters.

    The term Frontmatter originated with the publishing industry, referencing anything in the first section of a book, for example, a Table of Content, or a Preface.

    January 10, 2018 - 1 minute read - regex javascript