Lookahead Conundrum

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
nfnasiuye12
Forum Newbie
Posts: 1
Joined: Sat Mar 08, 2008 11:26 pm

Lookahead Conundrum

Post by nfnasiuye12 »

I have a regular expression conundrum that I just can’t seem to work through.

I have an HTML document that has a series of items contained within strong tags each one followed by a random amount of text

Code: Select all

<strong>title 1</strong><br>
apple<br>orange<br>
<strong>title 2</strong><br>
pear<br>grape<br><item3<br>Apricot<br>
<strong>title 3</strong><br>
banana<br>
<strong>title 4</strong><br>
cranberry<br>durian<br>cherry<br>
I’m trying to figure out how, using preg_match_all, to capture the contents of one of those strong tags ONLY if I get a match for one of the items below it.

Let’s say, for example, I want to capture the content contained in the strong tags that immediately proceed a match on the word durian.

Any help would be greatly appreciated.
User avatar
GeertDD
Forum Contributor
Posts: 274
Joined: Sun Oct 22, 2006 1:47 am
Location: Belgium

Re: Lookahead Conundrum

Post by GeertDD »

I would first split the whole text up in an array of <strong> pieces. Then loop through them.
Post Reply