?
Solved

Regular Expression Question

Posted on 2003-02-24
5
Medium Priority
?
334 Views
Last Modified: 2008-03-17
I need a regular expression that will match every NEWLINE (\n) that is NOT followed by a date in the format:

mm/dd/yyyy

That is to say, It should NOT match these:

01/21/1993
01/22/1993

But should match:

Four score...
And seven...

I have an enormous text file that is the results of a database query, and unfortunately, the data in one of the fields is a CLOB that can, (and does,) contain newline characters.  Since the beginning of each legitimate line is always a date in the format mm/dd/yyyy between 1993 and 1998, I JUST want to keep those.

I know I can match the LEGIT lines with:

\n[01][0-9]/[0-3][0-9]/199[3-8]

But how do I match all newlines that do NOT match that?
0
Comment
Question by:SuperKarateMonkey
[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
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
mehdi earned 195 total points
ID: 8009433
Hi,

You can use the ^ character, which matches the beginning of the line, and of course invert the match with !~.  

something like this

while ($line=<FILEHANDLE>) {

  if ($line !~ /^[01][0-9]/[0-3][0-9]/199[3-8]/) {
    # sounds like these are the ones you *do* want

    print "line does not begin with date";

  } else {
    # and these you do not want
    #(leave teh else out if you wish to ignore these lines)
   
    print "line does begin with date";

  }
}

Thanks,

Mehdi
0
 
LVL 1

Expert Comment

by:mehdi
ID: 8009443
(assuming this is perl, othwewise the logic should still be the same)
0
 
LVL 2

Author Comment

by:SuperKarateMonkey
ID: 8009559
Unfortunately, that won't work:

I'm not using perl, java, C++, or any other robust language.  I'm using TextPad's search and replace feature, which only let's me find matches and then lets me replace them.

As such, all I can do is find exact matches, not non-matches.
0
 

Expert Comment

by:jespernaur
ID: 8045068
It's not quite clear what you want to achieve, but - have you considered defining a Textpad macro, which will find you legit lines and store them in an auxiliary buffer?
0
 
LVL 2

Author Comment

by:SuperKarateMonkey
ID: 8064933
Good enough, I suppose.
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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Introduction to Processes
Suggested Courses
Course of the Month8 days, 12 hours left to enroll

764 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