Jump to content

[SOLVED] Search for regex in text.


peeps

Recommended Posts

I have googled many different things, but I cannot grasp how to pull the text that matches the regular expression from text I want to look in. Maybe I just don't know how to word my question. I have tried preg_grep and am not sure that even does what I want to do. What I am doing now is:

$tosearch = explode(" ",$sometext);

foreach($tosearch as $value){
  	if(eregi('[A-Z0-9]{2}-[A-Z0-9]{2}-[A-Z0-9]{2}-[A-Z0-9]{2}-[A-Z0-9]{2}-[A-Z0-9]{2}',$value)){
	$mac = $value;
	}
}

that works, but what I want to do is:

$mac = preg_grep('[A-Z0-9]{2}-[A-Z0-9]{2}-[A-Z0-9]{2}-[A-Z0-9]{2}-[A-Z0-9]{2}-[A-Z0-9]{2}', $sometext); //$sometext not being an array

The above gives an error complaining about not being an array.

Thanks.

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/43183-solved-search-for-regex-in-text/
Share on other sites

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.