Solved

how to match/filter the lines in perl

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

Suggested Solutions

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…
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…

828 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