How to extract code block substring from string

This is my first post here so hopefully I’m not posting incorrectly, but I’m basically looking to extract the code block (substring wrapped in backticks) from a string that was returned from an API request.

Here is the string:

const originalString = 'this is some string and I want to extract ```the code contained in the backticks```';

const whatIWant = 'the code contained in the back ticks';

I was thinking maybe I could use regex, but I wasn’t able to come up with anything that would work.

I also tried using something like this:

originalString.substring(originalString .indexOf("```"), originalString .lastIndexOf("```") + 3);

but it produces undesired results when the text contains a mix of normal text and multiple code blocks.

Any ideas?