dtdetu Posted November 16, 2008 Share Posted November 16, 2008 Hello how can i get the 10 from this code: (10:1)<br /> i tried this but didnt work, can someone help, thanks preg_match("~((.*?):1)~i", $string, $result); Link to comment https://forums.phpfreaks.com/topic/132949-solved-regex-question/ Share on other sites More sharing options...
ddrudik Posted November 16, 2008 Share Posted November 16, 2008 PHP Code Example: <?php $sourcestring="your source string"; preg_match_all('/\((\d+):\d+\)/',$sourcestring,$matches); echo "<pre>".print_r($matches,true); ?> $matches Array: ( [0] => Array ( [0] => (10:1) ) [1] => Array ( [0] => 10 ) ) Link to comment https://forums.phpfreaks.com/topic/132949-solved-regex-question/#findComment-691366 Share on other sites More sharing options...
.josh Posted November 16, 2008 Share Posted November 16, 2008 "/\((.*):/" Link to comment https://forums.phpfreaks.com/topic/132949-solved-regex-question/#findComment-691376 Share on other sites More sharing options...
dtdetu Posted November 16, 2008 Author Share Posted November 16, 2008 "/\((.*):/" i need to use ( and ) too otherwise it finds lots of things in html code, i am searching a html page not only that string:) also ddrudik it didnt work for me now also i dont need (10:1) it shouldnt be included in array. can u check again thanks Link to comment https://forums.phpfreaks.com/topic/132949-solved-regex-question/#findComment-691380 Share on other sites More sharing options...
.josh Posted November 16, 2008 Share Posted November 16, 2008 well you posted a certain string regex is based off that specific string. Anyways, ddrudik's regex should work for you regardless. Look at his array dump. Link to comment https://forums.phpfreaks.com/topic/132949-solved-regex-question/#findComment-691383 Share on other sites More sharing options...
dtdetu Posted November 16, 2008 Author Share Posted November 16, 2008 ok it works with the only (10:1) but when i use it on page it gives blank arrays, the string is like this Germany and 2 is variable, 1 is stable, i want to get the 2 <td>Germany (2 : 1)</td> Link to comment https://forums.phpfreaks.com/topic/132949-solved-regex-question/#findComment-691394 Share on other sites More sharing options...
dtdetu Posted November 16, 2008 Author Share Posted November 16, 2008 sorry i was making a mistake thats why it didnt work, thank you both sorry for mistake Link to comment https://forums.phpfreaks.com/topic/132949-solved-regex-question/#findComment-691396 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.