0

I am using Scriban to render a html template from a dynamic object and a html template in the form of a string.

I am trying to validate that the dynamic object contains all the field that i need to fill into the template.

To do this, i need to find all the parts of my template, that are delimited by "{{" at the beginning and "}}" in the end.

My html template is a string, and could look like this:

"<ul id='object'>\n<h2>Name 2: {{ object.Username }}</h2>\n<h1>Message 2: {{ object.Password }}</h1>\n</ul>"

The dynamic object that fits the above html template would have to contain a Username field, and a Password field.

I would like to derive the needed parts of the string as a collection of substrings. I have been looking into Regex, but i am very green in that field, and would appreciate any help i could get.

To be totally clear, the output im looking for in the example above (the "code snippet"), is a collection of strings containing "object.Username" and "object.Password".

Bille
  • 371
  • 6
  • 15
  • 1
    It's a little unclear (maybe it's just me!) what you're asking. If you are needing a regex, providing an example of what the input would look like would be very helpful. – Pooli Feb 27 '19 at 13:20
  • Hi! Sorry if i was unclear. The html template is in the form of a string, at the point where i want to derive the substring. I have edited the post to make it more clear. – Bille Feb 27 '19 at 13:25
  • 1
    If your string is HTML, try to parse it then get your desired values. For example refer to **[this post](https://stackoverflow.com/questions/56107/what-is-the-best-way-to-parse-html-in-c)**. – Sá´‡M Feb 27 '19 at 13:31

0 Answers0