?
Solved

Regular Expression Question

Posted on 2003-02-24
5
Medium Priority
?
345 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
  • 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

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

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

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

616 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