Solved

how to match/filter the lines in perl

Posted on 2009-06-30
5
211 Views
Last Modified: 2012-05-07
Want to filter the lines formed by the 3 parts:
part1 part2 part3
separated by spaces and tabs.
part1 contains alphanumeric, (), -, and _
part2 and part3 are digits.
For example,
A1-(ABC)XX1_(C)DE10     1223345    323242
XX10_1(2)                             98765       67890
For only part2 and part3, it's something like
$_ =~ /^\d+\s+\d+$/
to filter it. How to do it if considering all 3 parts?
0
Comment
Question by:jl66
  • 2
  • 2
5 Comments
 
LVL 40

Assisted Solution

by:mrjoltcola
mrjoltcola earned 30 total points
ID: 24746678
You could probably use, since there are no embedded spaces in each element.


/^(\S+)\s+(\S+)\s+(\S+)/
0
 
LVL 7

Expert Comment

by:rcflyr
ID: 24746727
if you have to verify that it meets the exact requires you specified:
$_=~/^([0-9a-zA-Z\(\)\-_]+)\s(\d+)\s(\d+)/

Open in new window

0
 

Author Comment

by:jl66
ID: 24747289
mrjoltcola, I want to verify the data, so the inputs have to follow some patterns.
rcflyr, it did not work. I used the above two lines as an example.
0
 

Author Comment

by:jl66
ID: 24747310
continued --rcflyr, it did not work. I used the above two lines as an example. It gave two "bad" lines
0
 
LVL 7

Accepted Solution

by:
rcflyr earned 470 total points
ID: 24747393
apologies, forgot the + after \s

I tested this one with both of your lines.
$_=~/^([0-9a-zA-Z\(\)\-_]+)\s+(\d+)\s+(\d+)/

Open in new window

0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

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 …
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…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

813 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

15 Experts available now in Live!

Get 1:1 Help Now