Title: preg_match_all
Last modified: August 20, 2016

---

# preg_match_all

 *  [swingprofessors](https://wordpress.org/support/users/swingprofessors/)
 * (@swingprofessors)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/preg_match_all/)
 * I am using the code below to search for the first image in a post:
 *     ```
       preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
       	if ( isset( $matches ) ) {
       	$url = $matches[1][0];
       	}
       ```
   
 * I really want to search for the first image in a post that has an underscore “_”
   in the url, can this be done?

Viewing 1 replies (of 1 total)

 *  Thread Starter [swingprofessors](https://wordpress.org/support/users/swingprofessors/)
 * (@swingprofessors)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/preg_match_all/#post-2248782)
 * I know there is probably a simple solution but can anyone please help?

Viewing 1 replies (of 1 total)

The topic ‘preg_match_all’ is closed to new replies.

## Tags

 * [php](https://wordpress.org/support/topic-tag/php/)
 * [preg_match_all()](https://wordpress.org/support/topic-tag/preg_match_all/)

 * 1 reply
 * 1 participant
 * Last reply from: [swingprofessors](https://wordpress.org/support/users/swingprofessors/)
 * Last activity: [14 years, 11 months ago](https://wordpress.org/support/topic/preg_match_all/#post-2248782)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
