Solved

how to match/filter the lines in perl

Posted on 2009-06-30
5
210 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

920 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

16 Experts available now in Live!

Get 1:1 Help Now