--- Stefan Rotsch <[EMAIL PROTECTED]> wrote:
> Hi,
> 
> I've got trouble with matching a character only once. The function
> 
> my $filename = $File::Find::name;
> if ($filename =~ /(\~){1}$/) {  
>     # do something
> }
> 
> should be used for deleting temporary files ending with a ~. Because
> of some special files ending with ~~ I would like to keep the above
> pattern has to match _exactly one_ ~ at the end of a filename.
> 
> In my eyes, {1} seems to be the right way, but it won't work. I've
> already tried moving brackets or the $-sign around, but with no
> positive result. Any hints?
> 
> Regards,
> Stefan

Stefan,

There are two ways to accomplish this.  You want a negative lookbehind  or a negated 
character
class.  Use this for a quick demonstration:

    while ( <DATA> ) {
        print if /[^~]~$/;
    } 
    __DATA__
    1~
    2~~
    3~
    4~~

Or, you can use the following regex:  /(?<!~)~$/.

Cheers,
Curtis "Ovid" Poe

=====
Senior Programmer
Onsite! Technology (http://www.onsitetech.com/)
"Ovid" on http://www.perlmonks.org/

__________________________________________________
Terrorist Attacks on U.S. - How can you help?
Donate cash, emergency relief information
http://dailynews.yahoo.com/fc/US/Emergency_Information/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to