简体   繁体   中英

preventing regex to capture too early

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?

你匹配第一个<option value="所有东西,试着不匹配引号,即<option value="([^"]*)" selected > (意思是双引号之间只允许双引号:))。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM