Solved

'nother regexp question

Posted on 2000-04-15
4
244 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
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
jkstill earned 50 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
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…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

758 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