Operating System - Linux
1752513 Members
5041 Online
108788 Solutions
New Discussion юеВ

Using perl to control the characters type

 
SOLVED
Go to solution
Henry Chua
Super Advisor

Using perl to control the characters type

Hi guys,

Do you know how i can use perl scripting regular expression to control the input.

I would like the input to be 9 characters
1st character is alphabet, 2nd is digit, third alphabet follow by 6 digits. I am not sure how to control individual character.

Thanks in advance.

Best regards
Henry
3 REPLIES 3
Ermin Borovac
Honored Contributor
Solution

Re: Using perl to control the characters type

if ($var =~ /^[a-zA-Z]\d[a-zA-Z]\d{6}$/) {
/* do something */
}
H.Merijn Brand (procura
Honored Contributor

Re: Using perl to control the characters type

if you're new to re stuff, using the x modifier might help you understand it later


$var =~ m{
^ # Start of string
[a-z] # 1st A letter
\d # 2nd A digit
[a-z] # 3rd A letter
\d {6} # 4th 6 digits
$ # End of string
}xi; # x = allow space and comments (use \s to match space)
# i = ignore case

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Henry Chua
Super Advisor

Re: Using perl to control the characters type

Great help .. thanks guys!! :D