<?php
$html = '
<a href="./?pg=194">194</a><a href="./?pg=2" rel="next" class="next_page">2</a>
';

preg_match_all('/<a.*href="\.\/\?pg=(\d+)".*>(?:.*)<\/a>/', $html, $preg_matches);
echo max($preg_matches[1]);

