Solved

Matching pattern in PERL

Posted on 2008-10-10
9
210 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:atoncelli
  • 3
  • 3
  • 2
9 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 250 total points
ID: 22688600
/^ABS [A-Z][A-Z][A-Z] [0-9]\.[0-9]\.[0-9] A[0-9]+ B[0-9]+$/
0
 

Author Comment

by:atoncelli
ID: 22688703
That works! Thanks

What does the
+$
do?
0
 
LVL 39

Expert Comment

by:Adam314
ID: 22688806
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).
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 39

Expert Comment

by:Adam314
ID: 22689573
ozo had answered your original question... the points should have gone to him (or at least a split)
0
 

Author Comment

by:atoncelli
ID: 22689695
Oops!  I didn't noticed.  Very sorry about that.
 Is there a way to go back and fix it?
0
 
LVL 39

Expert Comment

by:Adam314
ID: 22690925
You'll have to post a question in community support referring to this question.  Explain what you want, and they will help you.
0
 

Author Comment

by:atoncelli
ID: 22692056
I did that.
Thanks
0
 
LVL 84

Expert Comment

by:ozo
ID: 22692776
see
perldoc perlre
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
pipe to sed or perl, please help 5 135
Convert grep lines to perl 6 75
Parse csv file and generate graphs in HTML in bash 8 272
Log File Creation with Header and Footer 17 153
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question