RE question

Dave Roe david_roe at mac.com
Fri May 14 12:29:34 CDT 2004


~sdpm~
On May 14, 2004, at 9:31 AM, Ken Loomis wrote:

> As a web designer that enjoys programming, I joined this group a few 
> years ago hoping to become proficient at PERL (or, is it Perl). I have 
> learned a lot from looking at the exchanges here, but have to admit 
> that RE's still baffle me.

It's Perl. You can learn a lot more at learn.perl.org and/or perldoc.

> I host a discussion board that is apparently being Spam'ed by hackers. 
> The board is in Perl and I would like an RE that will strip everything 
> except alphanumeric characters from the subject. For example, the 
> subject line should only contain A-Z, a-z & 0-9.

 From perldoc perlre:

            \w  Match a "word" character (alphanumeric plus "_")
            \W  Match a non-"word" character

> The subject line is contained in $FORM('subject'), so I'd like an RE 
> that will replace the contents of that variable with the stripped 
> version. also, I may decide to allow periods ('.'), and would like to 
> see how I'd have to modify that RE to allow that.

You probably meant $FORM{'subject'}. How about:

	$FORM{subject} =~ s/\W//g;

which means "change a non-word char into nothing, repeatedly".

	$FORM{subject} =~ s/[^\w\.]//g

uses a character class to change anything that is _not_ a word char or 
a period into nothing.

Seriously, read perldoc. Start with "perldoc perlrequick" and "perldoc 
perlretut".

HTH,
/dave

~sdpm~

The posting address is: san-diego-pm-list at hfb.pm.org

List requests should be sent to: majordomo at hfb.pm.org

If you ever want to remove yourself from this mailing list,
you can send mail to <majordomo at happyfunball.pm.org> with the following
command in the body of your email message:

    unsubscribe san-diego-pm-list

If you ever need to get in contact with the owner of the list,
(if you have trouble unsubscribing, or have questions about the
list itself) send email to <owner-san-diego-pm-list at happyfunball.pm.org> .
This is the general rule for most mailing lists when you need
to contact a human.




More information about the San-Diego-pm mailing list