Home > Software design >  How do I count the words in quotes in markdown files (using regex or another way)?
How do I count the words in quotes in markdown files (using regex or another way)?

Time:12-25

I'm writing a paper in markdown, and I need to make sure I’m not quoting too much (somewhere it says the text isn’t meant to include more than 10% direct quotes), so I’d like a way to count the words in quotes.

How is this possible?

I've tried messing with regular expressions, e.g. \“(.*?)\”, but that only gives me THAT there are words in quotes in certain files, I need to find out the amount of words that is.

I've also tried ([“”])(?:(?=(\\?))\2.)*?\1 and the same thing happens. I've also tried using grep with either of those regex searches in Terminal (I'm on Linux Mint) but neither have any output.

Any advice is appreciated.

CodePudding user response:

Download & install Visual Studio Code (if you don't have yet).

  • Insert your full text
  • ctrl F and click on .* (use regular expression)
  • insert your regex “(.*?)”. VSCode will find all the phrases/words surrounded by the quotes
  • ctrl shift L to select all the matches
  • copy them via ctrl C
  • open new file
  • ctrl V

This should give you a separate file with words inside quotes only. You can count number of words in it and number of words in the original file and get the result.

For word count (it is a bit approximate but should suit your needs), you can search for regex (\s|\n|\t) and see the number of found entries at the right of the search dialog. Or you can use plugins like https://marketplace.visualstudio.com/items?itemName=ms-vscode.wordcount to get exact word count in the file.

  • Related