Ajax自定义模板引擎

I have a project that is simulating an exam system, except that it needs to display custom questions. I have a question regarding implementing this dynamic question section.

Here is what I have so far:

{q::lecture1::2::all}

I am pulling all the questions into JS using AJAX and what I want to do is find everything between {} and render questions. For the example above, it should do the following:

find {q::lecture1::2::all} parse based off of ::, so that you have [q][lecture1][2][all] then on the [2] index pull questions from the AJAX question list, and render

I have the parsing/exploding step done, but I can't figure out how find all of the {} on a page, and then pull in the question list and render just x questions (based off of that third index)

Background: it has to be custom code, no external templating engines are allowed.

Thank you so much for the help.

EDIT: the first step is done as well.