Reputation: 8985
I have the following text which I will be running regex on. I want to match the "selected" option and get its value. In this example Haiti is the selected option.
<option value="502">Guatemala (+502)</option><option value="224">Guinea (+224)</option><option value="245">Guinea-Bissau (+245)</option><option value="592">Guyana (+592)</option><option value="509" selected >Haiti (+509)</option><option value="504">Honduras (+504)</option><option value="852">Hong Kong (+852)</option>
I tried this regex
<option value="(.*?)" selected >
which matches
224">Guinea (+224)</option><option value="245">Guinea-Bissau (+245)</option><option value="592">Guyana (+592)</option><option value="509
I want to match "509" only. Any solutions for this?
Upvotes: 0
Views: 57
Reputation: 88707
You're matching everything from the first <option value="
, try to not match the quotes instead, i.e. <option value="([^"]*)" selected >
(meaning anything but double quotes is allowed between the double quotes :) ).
Upvotes: 2