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
Solved

Matching pattern in PERL

Posted on 2008-10-10
9
204 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
crawling gofundme 4 132
add a syntax to a csv file 8 99
create a gui in perl 3 97
combine multiple lines 2 67
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…

791 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