Hi,

On Thu, May 06, 2010 at 08:48:35AM +0200, C.M. Burns wrote:
> 
> when creating a custom rule, what characters have to be escaped?

every character with special meaning in perl regular expressions
and in the place it's used. 

In example it's a big difference if ] is used in a 
character class or not (i.e. "[^\]]") or if { is part
of a repetition operator or not.

Just make some experiments: try to remove all but [ and ] from a string
perl -e '$a="[abc\]"; print $a, "\n"; $a =~ s/[^[]]//g ; print $a,"\n"'
perl -e '$a="[abc\]"; print $a, "\n"; $a =~ s/[^[\]]//g ; print $a,"\n"'
perl -e '$a="[abc\]"; print $a, "\n"; $a =~ s/[^\[\]]//g ; print $a,"\n"'

In general it should be save to escape [ *and* ]

...
> while in common regex on only [ must be escaped
> http://www.regular-expressions.info/characters.html

"]" must be escaped in any case perl tries to use it 
as closing bracket or limiter (i.e. for a character class).

For details have a look at perlrequick(1) and perlre(1) and 
perop(1) section "Regexp Quote-Like Operators"

Search for "special character" or "escape" or 
"parsing quoted constructs" 

HTH

-- 
Regards Frank

Reply via email to