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

regular expression question

Status
Not open for further replies.

redss

Programmer
Joined
Oct 20, 2002
Messages
195
$txt =~ s/.*foo// ...will delete everthing up to and including "foo"

How do you delete everything up to but NOT including the word foo?
 
I think I figured out an easy obvious answer...

$txt =~ s/.*foo/foo/;
 
this is another way to do it:-

$txt = "some text here foo";

print "$txt > ";

$txt =~ s/.*(foo)/[red]$1[/red]/;

print "$txt";


Duncan
 
Lets throw out another one:
Code:
$txt =~ s/.*(?=foo)//;
Lookaheads are zero width. See perldoc perlre for more.

________________________________________
Andrew - Perl Monkey
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top