Actually, \n's are the one thing that the $ anchor doesn't work exactly
right on.  Usually it's not a huge deal, but Perl will still match a line
that has a \n after the part that you are trying to match if you use $ to
anchor.  This is normally very useful, as in the case of a line of text
being read from a file.  Without this behavior you would have to put a \n at
the end of all of your regexes.  So:

$radentry =~ /\n\n$/;

will match "\n\n" and "\n\n\n" 

To fix this problem, you should remember the \Z anchor, which matches only
the end of a string.  

$radentry =~ /\n\n\Z/;

-----Original Message-----
From: Kevin Cornmell
To: '[EMAIL PROTECTED]'
Sent: 4/24/02 2:45 AM
Subject: RE: Patterm Matching

++++++++++++++++++++++++++++++++++++++++++++++++++
Please read the disclaimer at the bottom of this e-mail.
++++++++++++++++++++++++++++++++++++++++++++++++++ 

Or try anchoring that regex.

if ($radentry =~/\n\n$/){
        foo;
}

-----Original Message-----
From: John W. Krahn [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, April 24, 2002 10:42 AM
To: [EMAIL PROTECTED]
Subject: Re: Patterm Matching


Andrew Tait wrote:
> Hi All,

Hello,

> Quick question. How can I check if the last two characters of a string
are
> both new line's (i,e, \n)
> 
> This is what I have come up with so far:
> 
> if ($radentry =~ /"*\n\n/")

if ( substr( $radentry, -2 ) eq "\n\n" )


John
-- 
use Perl;
program
fulfillment


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


------------------------------------------------------------------------
---------------------------------------------
This email is intended for the named recipient(s) only. Its contents
are  confidential and may only be retained by the named recipient(s)
and may only be copied or  disclosed  with the consent of The London
Clearing House (LCH).    If you are not an intended recipient please
delete this e-mail and notify [EMAIL PROTECTED]

The contents  of this  email are  subject to  contract in all cases, 
and LCH makes no contractual commitment save where confirmed by hard
copy.  LCH accepts no liability, including liability for negligence, 
in respect of any statement in this email.

The London Clearing House Limited, Registered Office: Aldgate House, 
33 Aldgate High Street, London EC3N 1EA.    Recognised as a Clearing 
House under the Financial Services & Markets Act 2000. Reg in England
No.25932 
Telephone: 020 7426 7000              Internet: http://www.lch.co.uk
------------------------------------------------------------------------
---------------------------------------------

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

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

Reply via email to