?
Solved

'nother regexp question

Posted on 2000-04-15
4
Medium Priority
?
287 Views
Last Modified: 2010-03-05
How can I apply multiple conditions in a regexp, for example, if I open a file, and in a loop use the expression

print TEMPFILE if !/^Path: /;

to remove lies that start with Path: , how could I also remove lines starting with Subject: , Date: , etc.
0
Comment
Question by:frenomulax
[X]
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
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
jkstill earned 200 total points
ID: 2719989
First off, you should probably acquire a book that will help you with regular expressions, or just read the Perl documentation on it.

It will conserve your points. :)

Suppose you also want to remove all lines that begin with a drive letter, say C:, d:, e:, F:, etc.

What you need to do is a simple modification:

  print TEMPFILE if !/^Path:|^[A-Z|a-z]:/;

The bar '|' separates strings and/or character classes to check for.

If the other string to check for is simply a string, say 'Date:', then this would work:
 
   print TEMPFILE if !/^Path:|^Date:/;

0
 

Author Comment

by:frenomulax
ID: 2720002
I actually have been reading through programming perl, but I still have trouble w/ these. I had tried doing

if (!/Path: /) or (!/Date: /)...

and variations of this idea, but obviuosly that didn't work.

I will read up some more, always willing to tale suggestions for good references...
Thanks for your help.
0
 
LVL 3

Expert Comment

by:jkstill
ID: 2720036
Just keep working on it.

Regular expression can be hard when you are first learning them.

It gets easier with use, really!
0
 
LVL 84

Expert Comment

by:ozo
ID: 2720263
(!/Path: /) or (!/Date: /)
#is quivalent to
!(/Path: / and /Date: /)
#have you tried variations like
(!/Path: /) and (!/Date: /)
#or
!(/Path: / or /Date: /)
#or
!/Path: | Date: /
#or
print unless /^Path: / or /^Date: /;
#?


`perldoc perlre` might be the first reference to check.
then, as `perldoc -q book` suggests, you might want to read Mastering Regular Expressions by Jeffrey Friedl, which covers the subject in great depth.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
Six Sigma Control Plans
Suggested Courses

741 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