I am trying to parse a html document using javascript, its getting late and I am struggling a bit with the regex’s.
I have a document that contains the following:
<table>
{% for field in fields %}
<tr><td>{{field.label}}</td><td>{{field.value}}</td></tr>
{% endfor %}
</table>
Now i want to somehow select everything between {% for field in fields %} and {% endfor %} so that I can insert some fake figure into the label and value fields. Then I want to duplicate this section a few times so that it creates the wanted dummy output. Does anyone know an easy way to select everything between the for and endfor loop tags?
Thanks in advance.
Brief explanation of regex…
(?:{% for field in fields %}): Non capturing group (?:) to match opening “tag”([\s\S]*?):[\s\S]matches any character in JS regex (including newline)*matches 0 or more instances of the preceeding character class?makes the match lazy (so in this example it won’t potentially eat up a closing tag)(?:{% endfor %}): Non capturing group (?:) to match closing “tag”Flags
gim– global (ie match all in the input string) / case insensitive / multiline