Solved

how to match/filter the lines in perl

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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

20 Experts available now in Live!

Get 1:1 Help Now