Solved

Matching pattern in PERL

Posted on 2008-10-10
9
174 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
 
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now