Jump to content

[SOLVED] preg_match_all doesnt do what I want


tilt

Recommended Posts

$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?

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

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.

...

 

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:/

 

$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]);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.