On 12/30/2003 12:22 PM, Kevin Old wrote:

Hello everyone,

I found the subroutine below from a script that takes a string of text
and builds a regular expression out of it and incorporates that into a
rule for SpamAssassin.  It's worked quite well for my needs, but the
script has led to a few questions about the code and regex's.

My questions are:

1) Are the characters escaped in the subroutine *all* the characters
that *should* be escaped in a regex?

2) The author seems to think "this is crap code, there will be a better
way to do this".....thoughts, comments, suggestion on other ways this
can be done?


#escape stuff that would otherwise be regexp special
#this is crap code, there will be a better way to do this
sub escapebad {
my $string = $_[0];
$string =~ s/([\\\/[EMAIL PROTECTED](\)\<\>])/\\$&/g; #bad cha
rs turned good
return ($string);
}


Also anyone interested in the script for generating SpamAssasin rules,
let me know and I'll send you a copy.

Thanks for any help,
Kevin

If you have a string that is going to need escaping, consider using /\Q$string\U/ to handle quoting regex special chars.


Regards,
Randy.



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to