Regular expression to retrieve parameters inside select tag
I need to extract options into a 'select' special tag. Is it possible to use a single regex, or do I need to grab the inner html of the selection first and then the parameters? Here's an example html:
<select id="select_id">
<option selected value="">Select Type</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
.....
Thank.
source to share
While it is possible to create a regex that will do what you want, I really want you to be happier doing it through the DOM unless you have a reason not to use the DOM. There are no tags that suggest language or platform, so more specific information is difficult to get.
Any specific reason for trying to parse HTML with a regular expression rather than loading it into the DOM, or using the DOM available in the browser via Javascript?
If you only have a snippet like this, you can use
value="(\d*)"
Where (\ d *) will write the values โโof each option.
The problem I see is that you would need to narrow your search through a different regex to get such a simple query. Something like
<select.*>(.*?)</select>
in the outer loop will work in most cases. However, the DOM is your friend and avoids such hacks.
source to share