tilt Posted August 12, 2009 Share Posted August 12, 2009 $handresult = Full Tilt Poker Game #13864648535: $110 + $5 Heads Up Sit & Go (102264740), Table 1 - 15/30 - No Limit Hold'em - 21:01:44 ET - 2009/08/06 preg_match_all('/Full Tilt Poker Game #\\ (.*)\\ \\:/', $handresult, $pregresult4, PREG_PATTERN_ORDER); Hello all Im trying to get the number 13864648535 but im doing something wrong, it's not giving me anything Just " ". Could some1 help me out? Link to comment https://forums.phpfreaks.com/topic/169897-solved-preg_match_all-doesnt-do-what-i-want/ Share on other sites More sharing options...
avvllvva Posted August 12, 2009 Share Posted August 12, 2009 First of all I'm new to regex, and I'm not sure about this will help you !! any way check my code Why r u using preg_match_all? I can found that it will take more memory when compare to other string matching functions. here I'm assuming that u want to pull out the number between the # and : and the first occurance of both # and : will encloses the number. then try this code <?php $pos_hash = strpos($handresult,'#'); $pos_col = strpos($handresult,':'); echo substr($handresult,$pos_hash+1,$pos_col-1-$pos_hash); ?> Otherwise, leave this soln ... sorry Link to comment https://forums.phpfreaks.com/topic/169897-solved-preg_match_all-doesnt-do-what-i-want/#findComment-896326 Share on other sites More sharing options...
Mark Baker Posted August 12, 2009 Share Posted August 12, 2009 What's the #\\ in your regular expression. You're telling it to look for a hash, followed by a \, followed by a space, followed by the number you want. Your sample only has the hash. Similarly for the end of the number, you're telling it to look for a \, then a space, then another \ followed by a :, when your text only has the colon. Link to comment https://forums.phpfreaks.com/topic/169897-solved-preg_match_all-doesnt-do-what-i-want/#findComment-896336 Share on other sites More sharing options...
tilt Posted August 12, 2009 Author Share Posted August 12, 2009 ... Thanks, this works if the nr is always after the first # and always ends at the first :. Which in most cases works. ... If my sample is: PokerStars Game #31513778276: Tournament #186459712, $10.00+$0.50 USD Hold\'em No Limit - Match Round I, Level I (10/20) - 2009/08/11 21:55:52 CET [2009/08/11 15:55:52 ET] Table \'186459712 1\' 2-max Seat #1 is the button I can define the 31513778276 number with the function that avvllvva posted. But it doesn't work for the number in this piece:: Tournament #186459712, I now have this: preg_match_all('/Tournament #(.*)\\,/', $handresult, $pregresult4, PREG_PATTERN_ORDER); Which gives me: 186418144, $10.00+$0.50 USD Hold'em No Limit - Match Round I So somehow it skips the first ",". I cant figure out why:/ Link to comment https://forums.phpfreaks.com/topic/169897-solved-preg_match_all-doesnt-do-what-i-want/#findComment-896355 Share on other sites More sharing options...
Mark Baker Posted August 12, 2009 Share Posted August 12, 2009 Why do you keep putting \\ in the regexp? Try preg_match_all('/Tournament #(.*)[,:]/', $handresult, $pregresult4, PREG_PATTERN_ORDER); Link to comment https://forums.phpfreaks.com/topic/169897-solved-preg_match_all-doesnt-do-what-i-want/#findComment-896385 Share on other sites More sharing options...
tilt Posted August 12, 2009 Author Share Posted August 12, 2009 It still doesn't end at the first , preg_match_all('/Tournament #(.*)[,]/', $handresult, $pregresult4, PREG_PATTERN_ORDER); Gives 186418144, $10.00+$0.50 USD Hold'em No Limit - Match Round I Instead of 186418144 only :-\ Link to comment https://forums.phpfreaks.com/topic/169897-solved-preg_match_all-doesnt-do-what-i-want/#findComment-896403 Share on other sites More sharing options...
Mark Baker Posted August 12, 2009 Share Posted August 12, 2009 $testString = 'PokerStars Game #31513778276: Tournament #186459712, $10.00+$0.50 USD Hold\'em No Limit - Match Round I, Level I (10/20) - 2009/08/11 21:55:52 CET [2009/08/11 15:55:52 ET] Table \'186459712 1\' 2-max Seat #1 is the button'; preg_match_all('/#(.*)[:,]/U', $testString, $testResult, PREG_PATTERN_ORDER); print_r($testResult[1]); Link to comment https://forums.phpfreaks.com/topic/169897-solved-preg_match_all-doesnt-do-what-i-want/#findComment-896410 Share on other sites More sharing options...
tilt Posted August 12, 2009 Author Share Posted August 12, 2009 Thanks alot that works Link to comment https://forums.phpfreaks.com/topic/169897-solved-preg_match_all-doesnt-do-what-i-want/#findComment-896419 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.