Link to home
Start Free TrialLog in
Avatar of atoncelli
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
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of atoncelli
atoncelli

ASKER

That works! Thanks

What does the
+$
do?
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).
ozo had answered your original question... the points should have gone to him (or at least a split)
Oops!  I didn't noticed.  Very sorry about that.
 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.
I did that.
Thanks
see
perldoc perlre