Q:

Regex: Find ID in HTML element

I want to get the oID parameter from this HTML source with a regex condition:
<img src="button_print.gif" style="cursor:hand" onclick="window.open('http://domain.com/print_order.php?oID=5', 'popup', 'toolbar=0, width=640, height=600')">

I´ve tried many different ways now but I´m unable to find the right way.
For my understanding this regex should work (but it doesn´t):
oID=(\d+)

Maybe somebody has a hint for me?

A:

You have to replace the string before and after the match too:
.*?oID=(\d+).*

The command:
$string = '<img src="button_print.gif" style="cursor:hand" onclick="window.open(\'domain.com/print_order.php?oID=5\', \'popup\', \'toolbar=0, width=640, height=600\')">'; 
var_dump(preg_replace('/.*?oID=(\d+).*/','Output: $1',$string));

The result:
Output: 5

Online test.

