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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

non-greedy regex brainfart

Status
Not open for further replies.

skiflyer

Programmer
Sep 24, 2002
2,213
US
I'm usually ok on these, but am drawing a total blank today...

Here's what I want...
Code:
$string = " end end test sometext end end end ";

$outstr = " end end test othertext end end end ";

So my incorrect regex is basically
Code:
/test(.*)end/

But that obviouslly matches the last end resulting in
$outstr = " end end test othertext end";  (after I do the magic replacing stuff.

FIrst thing that pops to mind is
/test([^end])/

but that matches e|n|d, not the word end...
This can't be that hard, but I'm just not getting it today... any help?
 
And of course asking, is what makes my brain click...

Code:
/test(.*?)end/

Sorry for the wasted space.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top