Brad R Posted June 19, 2009 Share Posted June 19, 2009 Hi, I'm new. I've read the stickies, and couldn't find what I was looking for as I am so new to Regex that I was totally lost, lol. I even tried regexlib.net to no avail. I want to match <<####>> # = numbers, obviously, it can be any amount of numbers 0 - infinite. This is what I have been trying $pattern = "\<\</[^0-9]/\>\>"; And that doesn't work, It just matches all numbers, but I need them only to match if it is in the symbols << and >> and yes those are double < and > I am using this for an IRC bot. and the numbers represent topic numbers, and I am using the << and >> to trigger the command. Any help is appreciated. Million thanks in advance. Sorry if I didn't see something, feel free to call me a stupid loser and throw a topic link in my face. PS: I suppose I could use just one < and >, that's not a problem for me if it is a problem to use double < and > Quote Link to comment https://forums.phpfreaks.com/topic/162857-php-regex-match-numbers-within-symbols/ Share on other sites More sharing options...
Ken2k7 Posted June 19, 2009 Share Posted June 19, 2009 $pattern = '#<<\d+?>>#'; Quote Link to comment https://forums.phpfreaks.com/topic/162857-php-regex-match-numbers-within-symbols/#findComment-859348 Share on other sites More sharing options...
Brad R Posted June 19, 2009 Author Share Posted June 19, 2009 Thanks for your time, but that didn't seem to work. Here is the entire code, if this helps. <?php class plugGTopic{ public static function onText( event $event, $dh = null) { //Now I gotta get the title $subject = $dh->getircTrailing(); //$pattern = "\<\</[^0-9]/\>\>"; // These 3 $patterns have all been failures. //$pattern = '#<<\d+?>>#'; //$pattern = "/\<\<([0-9]?([^\]]+)\>\>/i"; if(preg_match_all($pattern, $subject, $matches)) { $dh->reply('Nice try, '.$dh->getIrcPrefixNickname().' but the parameters you entered: "'.$dh->getircTrailing().'" must not be number(s). You have to use a number, hence the parameters of this command which are: <topic _NUMBER_ >.'); } else { $page = file_get_contents('http://forums.tyreus.com/index.php?showtopic='.$dh->getircTrailing()); $title = explode("<title>", $page); $title = explode("</title>", $title[1]); $title = explode(" - ", $title[0]); //Shout it out! if($title[0] == "Board Message"){ $dh->reply('Sorry '.$dh->getIrcPrefixNickname().', But topic number '.$dh->getircTrailing().' isn\'t found!'); } else{ $dh->reply(''.$title[0].' - http://forums.tyreus.com/index.php?showtopic='.$dh->getircTrailing().''); $event->delete(); } } } } Quote Link to comment https://forums.phpfreaks.com/topic/162857-php-regex-match-numbers-within-symbols/#findComment-859353 Share on other sites More sharing options...
Ken2k7 Posted June 19, 2009 Share Posted June 19, 2009 Uh, it should work. Can you var_dump $subject? Here's a test run I created: $ more file.php <?php $e = '<<9372409210943>>'; preg_match('#<<\d+?>>#', $e, $match); var_dump($match); $ php file.php array(1) { [0]=> string(17) "<<9372409210943>>" } Quote Link to comment https://forums.phpfreaks.com/topic/162857-php-regex-match-numbers-within-symbols/#findComment-859395 Share on other sites More sharing options...
thebadbad Posted June 19, 2009 Share Posted June 19, 2009 If it can be any amount of numbers, use an * instead of a + in the pattern. So if I read your code right, the script should trigger an error if e.g. <<>> or <<866789>> is found anywhere in $subject? Is that right? I can't make sense of it when I read the error message, saying "(...) the parameters you entered must not be number(s). You have to use a number (...)". Quote Link to comment https://forums.phpfreaks.com/topic/162857-php-regex-match-numbers-within-symbols/#findComment-859483 Share on other sites More sharing options...
Brad R Posted June 19, 2009 Author Share Posted June 19, 2009 I got it to work, thanks for you time guys! (Mark as Resolved Please. ) Quote Link to comment https://forums.phpfreaks.com/topic/162857-php-regex-match-numbers-within-symbols/#findComment-859605 Share on other sites More sharing options...
thebadbad Posted June 19, 2009 Share Posted June 19, 2009 Mark as Resolved Please. That's your job; I believe the link is found at the bottom right of the page (It's literally years ago since I last created a topic, LOL ) Quote Link to comment https://forums.phpfreaks.com/topic/162857-php-regex-match-numbers-within-symbols/#findComment-859620 Share on other sites More sharing options...
Ken2k7 Posted June 20, 2009 Share Posted June 20, 2009 Bottom left IIRC. Quote Link to comment https://forums.phpfreaks.com/topic/162857-php-regex-match-numbers-within-symbols/#findComment-860019 Share on other sites More sharing options...
nrg_alpha Posted June 20, 2009 Share Posted June 20, 2009 Since the topic still isn't flagged as resolved, perhaps the OP needs to see the button for this (I'd rather the OP flag it than myself - gets him to learn where it is for the next time). Quote Link to comment https://forums.phpfreaks.com/topic/162857-php-regex-match-numbers-within-symbols/#findComment-860137 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.