Solved

'nother regexp question

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

912 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

25 Experts available now in Live!

Get 1:1 Help Now