Title: Message
Check the docs on perl regexp.  Most metacharacters do not need to be escaped with the backslash when they are used in a character class (they don't act as metacharacters when between []).  The caret (^) will negate the character class if it is the first thing following the opening bracket - so I would just move that to another place in the class.  That may not change how your match works, but it will certainly improve readability.  Also, I believe you'll need parentheses to make your backreference.  Try something like (this is untested):
 
if ($LogLinePrefix =~ /[][^$_*?.|(){}\\]*/)
    {
        $LoglinePrefix =~ s/([][^$_*?.|(){}\\]*)/\\{$1}/g;
    }
 
The parentheses setup your pattern memory for the $1 back reference in your substitution.
 
Hope that helps.
 
Chad
 
 
 
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED]
Sent: Friday, August 26, 2005 7:53 AM
To: [email protected]
Subject: Metacharacters


Morning,

I am working on some code which will check for a line starting with any Perl Metacharacters, and precede it with a '/'.
Here is what i have thus far:

                        if ($LogLinePrefix =~ /[\^\$\+\*\?\.\|\(\)\{\}\\\[\]]/)
                                {
                                        $LoglinePrefix =~ s/[\^\$\+\*\?\.\|\(\)\{\}\\\[\]]*/\\{$1}/g ;
                                }

Unfortunately, this isn't working.  Can anyone make a suggestion?

Regards/Thanks


Chris McEwen
Sr. Configuration Management Analyst
Alcatel Canada Inc.
Office: 416.748.4424 ext 5015
mailto: [EMAIL PROTECTED]
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to