--- On Tue, 11/4/08, Pete <[EMAIL PROTECTED]> wrote: > Thanks for that, but I was looking for a more generic answer. "the > first... (anything) after you have found the start of the phrase". > I suspected that it was ?, which makes reg "ungreedy", stops it as > soon as it can. But I couldn't get the syntax correct, so I assumed > that I was wrong. > > I eventually found this: > "/<div(.*?)>/"; > > The ? is the magic extra touch that was missing. It means > "everything from "<div" to the first ">". So I can now use those > two as variables in a class that will remove whatever I specify. > > -- > Pete Clark
Yes, your problem is clearly one of greedy matches being the default for regex. Your method of using the question mark to suppress this behavior is one I might use. Here is another consideration. You can use strip_tags() and allow only the tags you want, such as <p>: $in = "<div class='abc'><div align='left'><p>Text wanted</p></div></div>"; $out = strip_tags($in, '<p>'); James Keeline