I need to parse HTML files and extract any characters found within the following flag:
${message}
The message may contain words, whitespace, and even special characters. I have the following regex that seems to partially work:
/\$\{(.+)\}/g
What's happening with this pattern is it appears to be working backwards from the line break and finding the first }. The desired result would be to work forward and find the first }.
Here is the regex in RegExr: https://regexr.com/3ng3d
I have the following test case:
<div>
<div class="panel-heading">
<h2 class="panel-title">${Current Status}<span> - {{data.serviceDisplay}}</span></h2>
</div>
${test}
<div class="panel-body">
<div>${We constantly monitor our services and their related components.} ${If there is ever a service interruption, a notification will be posted to this page.} ${If you are experiencing problems not listed on this page, you can submit a request for service.}</div>
<div>
<div>${No system is reporting an issue}</div>
</div>
<div>
<a>{{outage.typeDisplay}} - {{outage.ci}} (${started {{outage.begin}}})
<div></div>
</a>
</div>
<div><a href="?id=services_status" aria-label="${More information, open current status page}">${More information...}
</a></div>
</div>
</div>
The regex should extract the following:
- Current Status
- test
- We constantly monitor our services and their related components.
- If there is ever a service interruption, a notification will be posted to this page.
- If you are experiencing problems not listed on this page, you can submit a request for service.
- No system is reporting an issue
- started {{outage.begin}}
- More information, open current status page
- More information...
But what I'm actually getting is...
- ${Current Status} - {{data.serviceDisplay}}
- ${test}
- ${We constantly monitor our services and their related components.} ${If 4. there is ever a service interruption, a notification will be posted to this page.} ${If you are experiencing problems not listed on this page, you can submit a request for service.}
- ${No system is reporting an issue}
- ${started {{outage.begin}}}
- ${More information, open current status page}">${More information...}
It appears my regex is working back from the \n and finding the first } which is what's giving me #1, #3, and #6.
How can I work from the start and find the first } as opposed to working backwards from the line break?
/\$\{(.+?)\}/gshould give you closer to what you want (you need lazy matching instead of greedy), but it still has issues with #7.