...

View Full Version : simple match question



dkenney1
12-30-2009, 12:44 AM
I want to filter scalars to be numbers, letters, -, and maybe a space if they dont hyphenate their last name ( part of which to be anything else). like:

($text !~ /^[w -}/) or is it like $text =~ s/{A-Za-z0-9}*/ /g ?
How close am I?

oesxyl
12-30-2009, 01:01 AM
I want to filter scalars to be numbers, letters, -, and maybe a space if they dont hyphenate their last name ( part of which to be anything else). like:

($text !~ /^[w -}/) or is it like $text =~ s/{A-Za-z0-9}*/ /g ?


$text !~ /[^\w\s-]+/;

second is a substitute, not a match, and will remove any char if is in A-Z, a-z or 0-9, that if you replace { and } with [ and ], :)

best regards

bazz
12-30-2009, 01:02 AM
I would try:



unless ( $variable =~ /^[-a-zA-Z0-9 ]+$/ ) {
exit;
}


or, to allow underscores as well...



$variable =~ /^(-\w\ )+$/


not tested

bazz



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum