briant Posted June 4, 2009 Share Posted June 4, 2009 These regular expressions are so hard to understand. Anyone know of a really good tutorial? My problem is this. $content = "<h2>hi</h2> 123 (cats)<br> 456 (dogs)<br> 789 (fishes)"; I want to be able to match 456 because of dogs. Usually I can do it if the pattern is before but since this is after, how can I do it? PS: This is for content I have no control over, so I can't change the content. Link to comment https://forums.phpfreaks.com/topic/160891-solved-preg_match-help/ Share on other sites More sharing options...
gevans Posted June 4, 2009 Share Posted June 4, 2009 There is a good starting tutorial here at phpfreaks http://www.phpfreaks.com/tutorial/regular-expressions-part1---basic-syntax Also the sub forum http://www.phpfreaks.com/forums/index.php/board,43.0.html would've been a good starting place for your post! Link to comment https://forums.phpfreaks.com/topic/160891-solved-preg_match-help/#findComment-849097 Share on other sites More sharing options...
gevans Posted June 4, 2009 Share Posted June 4, 2009 my regex isn't brilliant, but this should work; <?php preg_match('/([0-9]+) \(dogs\)/', $content, $matches); echo $matches[1]; ?> Link to comment https://forums.phpfreaks.com/topic/160891-solved-preg_match-help/#findComment-849102 Share on other sites More sharing options...
briant Posted June 4, 2009 Author Share Posted June 4, 2009 Oh sorry, I should have looked through the other forums. Thank you for your help. I will try that out and let you know. I will try to read the tutorial as well. If it doesn't work out, I think I will just do a strstr function to get what I want. Thanks for your assistance. Link to comment https://forums.phpfreaks.com/topic/160891-solved-preg_match-help/#findComment-849104 Share on other sites More sharing options...
briant Posted June 4, 2009 Author Share Posted June 4, 2009 It worked, thanks so much. My example was kind of stupid since the numbers 456 should've been anything including letters. But I'll figure it out. Thanks for your example gevans. You've been more than helpful. Link to comment https://forums.phpfreaks.com/topic/160891-solved-preg_match-help/#findComment-849107 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.