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

Simple RegEx problem

Status
Not open for further replies.

not4google

Programmer
Nov 6, 2006
15
0
0
GB
Hi all,

I am trying to match the following:

$text = "abcdef-TO";

if($text =~ /-TO/){
#do something here
}

This doesnt seem to work, something to do with the "-" as in "-TO"?

I have tried escaping it but no joy, any help much appreciated,

Cheers,
 
Hi all,

Sorry ignore this thread the above is working fine I had another condition in there which was preventing this from working correctly,

Cheers,
 
Your example looks OK. Perhaps there is a typo in your real code. The "-" is a valid RegEx test, often used when checking numbers to see if there is an optional preceeding minus sign.

Do use 'pragmas' such as:
use strict;
it will help to prevent typo's.

I hope that helps.

Mike
 
Sorry. I started typing, got interrupted by the phone, then carried on.

Regards.

MIke
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top