Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

'nother regexp question

Posted on 2000-04-15
4
Medium Priority
?
293 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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

609 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