Jump to content

Problem with alternative regexp


Liquix

Recommended Posts

I got this regexp:

$regexp = '#<div class="profile-info">.*?name-text">(.*?)</span>.*?birthday date.*?\s+([\S]+).*?<div>.*?([ ]+<img src="([^"]+))*.*?<div class="profile-figure">.*?src="([^"]+).*?</div>.*?<div class="profile-motto">(.*?)<div#sm';

 

In the code you can find this:

([ ]+<img src="([^"]+))*

 

There is a crash between backtrace and making the string between the outer braces alternative there. If the code between the outer braces isn't in the text Im searching in, I want ([^"]+) to return an empty variable instead of making the whole regexp crash! Any way to do this?

 

(The * at the end is to make the content of braces be one or zero times)

 

Link to comment
https://forums.phpfreaks.com/topic/50175-problem-with-alternative-regexp/
Share on other sites

Im searching for different information from an external webpage. In PHP the () is used as backtraces to get infromation to an array. One of the elements I want to add to the array is alternative and isnt always set.. I want the var to be empty if the specific image isnt in the code

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.