Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Non-Greedy Regular Expression

Status
Not open for further replies.

tweenerz

Programmer
Mar 25, 2002
202
US
Dont know if this is the right forum, but I couldnt find a 'regexp' forum and I figure most Perl programmers are good with regexp's.

I have this text for example:

Lorem ipsum dolor sit amet<div align="justify">Lorem ipsum dolor sit amet, consectetuer adipiscing elit<P>Lorem ipsum dolor sit amet, consectetuer adipiscing elit<B>Lorem Ipsum</B>Lorem ipsum dolor sit amet, consectetuer adipiscing elit</P></div></td></tr></table></div>Lorem ipsum dolor sit amet

I want everything between '<div align="justify">' and the first '</div>' tag following it. Everything I have tried is greedy and gets everything until it finds the last </div> tag. Note: '<div align="justify">' only appears once in the searchable text.

Any ideas?
 
Never Mind - after a little more experimentation - I figured it out:

<div align="justify">(.*?)</div>

It was that damn question mark - I couldnt figure out where to place it. Sometimes it is just too simple.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top