Hi guys, I'm already very desperate with a regular expression trying to match a piece of text, please help: This is the text: <OPTION value="25">Anglicky</OPTION> <OPTION value="19">Auto, moto</OPTION> <OPTION value="39">StavebnÃctvo</OPTION> <OPTION value="39">staveb</OPTION> <OPTION value="26">Å kolstvo</OPTION> And I need to select only <OPTION value="39">StavebnÃctvo</OPTION> however not literally - its parts change as well. So far I got this: (?<=\<OPTION).*?(?i)staveb.*?(?=\</OPTION\>) The problem is that it matches also the text before my desired selection. Pleeease help me!!! thank you very much
try this $s = '<OPTION value="25">Anglicky</OPTION> <OPTION value="19">Auto, moto</OPTION> <OPTION value="39">StavebnÃctvo</OPTION> <OPTION value="39">staveb</OPTION> <OPTION value="26">Å kolstvo</OPTION>'; $pattern = '#(<option value="\d+">staveb[^<]+</option>)#si'; if (preg_match($pattern, $s, $m)) { print_r($m); } Code (markup):