2021年4月30日星期五

Regex to append extension to file path

I'm trying to get running a GitHub action link checker that checks markdown files for URLs. I have a Jekyll site.

The link checker looks for files, rather than full URLs, as a result:

This fails - /docs/article1/

But this works - /docs/article1.md

I have the following rewrite in place that works for most use cases:

{    "pattern": "(\\S+)\/(\\s|$)",    "replacement": "$1$2"  }  

However, it does not work if the trailing slash is missing from the the link.

Can someone recommend a regex update that will capture either:

  • /docs/article1/
  • /docs/article1

And rewrite it as /docs/article1.md?

https://stackoverflow.com/questions/67340885/regex-to-append-extension-to-file-path May 01, 2021 at 05:54AM

没有评论:

发表评论