Skip to content

Instantly share code, notes, and snippets.

@chrisroos
Created September 11, 2015 11:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisroos/92d4221c47f1396d0e76 to your computer and use it in GitHub Desktop.
Save chrisroos/92d4221c47f1396d0e76 to your computer and use it in GitHub Desktop.
Using pcregrep to extract reference links from Markdown documents

Using grep (well, pcregrep) to display the labels of reference style links in a Markdown document:

$ pcregrep --only-matching=1 \  # Only display the match from group 1
  "\[.*?\](\[.*?\])" \          # Find [text][label] reference style links
  /path/to/document.md | \      # Path to the markdown document
  sort                          # Optionally sort the output

I had the regexp working in grep but couldn't capture just the group I was interested in. This Stack Overflow answer suggested pcregrep.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment