Solved

'nother regexp question

Posted on 2000-04-15
4
270 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Title # Comments Views Activity
Perl script to parse xml file 2 125
syslog unix file 20 76
Replace  text in a file 2 114
perl: Cleaning meta tags using RegEX 12 82
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…

861 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