atoncelli
asked on
Matching pattern in PERL
Hello,
I need to verify a string from the command line in a PERL script. I need to make sure that the string has the following format:
ABS <A-Z><A-Z><A-Z> <0-9>.<0-9>.<0-9> <A-Z><number> <A-Z><number>
here is a sample:
ABS MSI 9.8.5 A209 B203
ABS HGF 9.8.5 A1234 B6456
i.e. of not valid strings:
SABS MSI 9.8.5 A209 B203
ABS HGF 19.8.5 A1234 B6456
ABS MSI 9.84.5 A209 B203
ABS HGF 9.85.5 A1234 B6456
ABS MSI 9.8.5 A209 B203D
ABS HGF 9.8.5 AB1234 B6456
(in words: ABS 3 letters, space, number.number.number letternumber letternumber)
String needs to start with ABS, then the rest of the sequence.
This is what I was trying but it is not working:
($LABEL =~ /^ABS [A-Z][A-Z][A-Z] [0-9]\.[0-9]\.[0-9] A[0-9][0-9][0-9] B[0-9][0-9][0-9]/))
Thanks
I need to verify a string from the command line in a PERL script. I need to make sure that the string has the following format:
ABS <A-Z><A-Z><A-Z> <0-9>.<0-9>.<0-9> <A-Z><number> <A-Z><number>
here is a sample:
ABS MSI 9.8.5 A209 B203
ABS HGF 9.8.5 A1234 B6456
i.e. of not valid strings:
SABS MSI 9.8.5 A209 B203
ABS HGF 19.8.5 A1234 B6456
ABS MSI 9.84.5 A209 B203
ABS HGF 9.85.5 A1234 B6456
ABS MSI 9.8.5 A209 B203D
ABS HGF 9.8.5 AB1234 B6456
(in words: ABS 3 letters, space, number.number.number letternumber letternumber)
String needs to start with ABS, then the rest of the sequence.
This is what I was trying but it is not working:
($LABEL =~ /^ABS [A-Z][A-Z][A-Z] [0-9]\.[0-9]\.[0-9] A[0-9][0-9][0-9] B[0-9][0-9][0-9]/))
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The + means one or more of what is before it.
The $ at the end means end of line (a $ in the middle will be interpreted as a variable name).
The $ at the end means end of line (a $ in the middle will be interpreted as a variable name).
ozo had answered your original question... the points should have gone to him (or at least a split)
ASKER
Oops! I didn't noticed. Very sorry about that.
Is there a way to go back and fix it?
Is there a way to go back and fix it?
You'll have to post a question in community support referring to this question. Explain what you want, and they will help you.
ASKER
I did that.
Thanks
Thanks
see
perldoc perlre
perldoc perlre
ASKER
What does the
+$
do?