$re = '/(?xi) # i-flag for caseless, x-flag for comments (free spacing mode)
# 1.) match <select with optional space at the end
<\s*select\s[^>]*?\bname\s*=\s*["\']\s*quantity[^>]*>\s*
# 2.) match lazily any amount of options until the "selected"
(?:<\s*option[^>]*>\s*)*?
# 3.) match selected using a lookahead and capture number from value
<\s*option\s(?=[^>]*?\bselected)[^>]*?\bvalue\s*=\s*["\']\s*(\d[.,\d]*)/';
$str = '<select attr="other stuff" name="quantity">
<option value="1" />
<option value="2" selected="selected" />
</select>
....
<select name="quantity" attr="other stuff">
<option selected="selected" value="5" />
<option value="6" />
</select>
....
<select name="quantity" attr="other stuff">
<option value="6" />
<option value="6" />
<option value="6" />
<option value="6" />
<option selected value= " 777.7 " />
<option value="6" />
</select>
';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php