Jump to content

Display part of Regex Search


abhi_madhani

Recommended Posts

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

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

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.