Home: Perl Programming Help: Regular Expressions:
need some help



pyojeok
Deleted

Jan 22, 2001, 9:32 AM


Views: 2865
need some help

Can someone explain to me what does this expression does? I think it checks for digits and maybe characters but I am not sure. Thanks.

($argument =~ /^[sS][cC][\d+][\w*]/)



japhy
Enthusiast / Moderator

Jan 22, 2001, 10:12 AM


Views: 2862
Re: need some help

I think the author didn't know what they were doing...


Code
m{ 
^ # beginning of string
[sS] # an 's' or 'S'
[cC] # a 'c' or 'C'
[\d+] # a digit (0-9) or '+'
[\w*] # a word char (a-z, A-Z, 0-9, _) or '*'
}x

I suspect it was meant to be:


Code
$string =~ /^sc\d+\w*/i;

The /i modifier there allows case-insensitive matching, meaning the 's' can match either an 's' or an 'S'.

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author