I have access to a large amount of HTML inside a single string:
const { body_html } = this.props.product_page;
I am attempting to update this HTML using only string parsing. Specifically, I want to find the first div closing element after a specific substring is found:
product.description
.
The challenge is the dynamic nature of product_page
. There will be an unknown amount of characters between the first closing div </div>
and the end of the substring product.description
How can I inject <div>Hello, world!</div>
after the first closing div -- after finding the product description variable?
EDIT: I know it's poor practise to modify HTML in such a fashion, but due to technical constraints, these are the conditions I have to satisfy. Also, this is not pure HTML code, but liquid code actually (embedded Ruby templates). Finally, I never asked for regex specifically. Can't indexOf with substrings be enough (or is that technically the same thing)?