Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Matching pattern in PERL

Posted on 2008-10-10
9
Medium Priority
?
225 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
9 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 1000 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
Technology Partners: 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
Six Sigma Control Plans

618 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