Vladimir Shevchenko
Vladimir Shevchenko

Reputation: 169

PHP Regex - Looking for all symbols except the word

I am using regexp on PHP. I have the text similar to the next(I have simplified it pretty much):

<table id="different_every_time" …><a href="url" …>Link</a>
… Intro text<table> … This is place for menu</table>
<table>Content</table></table>

I need to grab the text between the first tag and the second tag So the result is supposed to be:

id="different_every_time" …><a href="url" …>Link</a>… Intro text

I have tried next pattern:

(?<=<table)(.+)(?=<table)

But it returns me everything between the first <table> and the last <table>. I need to replace (.+) for something like (everything except ). May be there is easier solution. Any help is appreciated.

Upvotes: 0

Views: 67

Answers (1)

Halcyon
Halcyon

Reputation: 57703

Change (.+) to (.+?) to make it not greedy. It will try to match as little as possible, instead of as much as possible, ie: greedy.

Upvotes: 1

Related Questions