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

Regex question

Status
Not open for further replies.

lza

Programmer
Apr 22, 2002
26
AT
Hello

I have a regex question.
I'm trying to find out how to match everything but one word.
The string to match will contain only one word.
For example, if the string contains "TEST1", the regex expression
should accept the match for any word, but not
when this is TEST1.

Regards
Leandro
 
this is not a regex question

$text = 'TEST1';

if ($text eq "TEST1") {
print "exclude\n";
} else {
print "include\n";
}


the above example will EXCLUDE as the value of the variable is equal to 'TEST1' - any other value would include as it will fail to meet the match criteria


Kind Regards
Duncan
 
Hello Duncan

I know that I do not need regex in Perl to do this, but I need the regex expression for another reason.
Any suggestion?

Regards
Leandro
 
Well it don't get any better:

$text =~ s/(.*(TEST1).*)/$1/;

You might want to make the .* non-greedy and you will probably run into trouble (especially under use strict) if the string contains TEST1 only.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top