abhi_madhani Posted April 1, 2011 Share Posted April 1, 2011 Hi, I am using a PHP's preg_match() to search through string, and displaying its pattern, but want to display only part of it. E.g. looks like preg_match('/shape=\'.*\'/sU',$value,$matches); The search displays " class='PHPfreaks' " From the search I would like to display only the part highlighted in bold. " '/shape=\'.*\'/sU' " So the final value to be displayed should be " PHPfreaks " Regards, Abhishek Link to comment https://forums.phpfreaks.com/topic/232423-display-part-of-regex-search/ Share on other sites More sharing options...
dcro2 Posted April 1, 2011 Share Posted April 1, 2011 I'm a little confused if you want the shape or class, but I think you want to put a subpattern in with parentheses: preg_match('/shape=\'(.*)\'/sU',$value,$matches); Then the match inside the parentheses will be inside $matches[1] Here's more about subpatterns: http://www.php.net/manual/en/regexp.reference.subpatterns.php Link to comment https://forums.phpfreaks.com/topic/232423-display-part-of-regex-search/#findComment-1195674 Share on other sites More sharing options...
abhi_madhani Posted April 2, 2011 Author Share Posted April 2, 2011 Hey Works like charm. Thanks a lot, I just learned about Regex basics, and hadn't come across sub patterns till now, very useful. Regards, Abhishek Link to comment https://forums.phpfreaks.com/topic/232423-display-part-of-regex-search/#findComment-1195810 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.