Closed Thread Icon

Preserved Topic: More Regexp Mania!!!!! Pages that link to <a href="https://ozoneasylum.com/backlink?for=21076" title="Pages that link to Preserved Topic: More Regexp Mania!!!!!" rel="nofollow" >Preserved Topic: More Regexp Mania!!!!!\

 
Author Thread
jiblet
Paranoid (IV) Inmate

From: Minneapolis, MN, USA
Insane since: May 2000

posted posted 10-03-2001 17:37

Okay, so I want to find the first line that doesn't start with a certain word. I know you can use negative classes [^things] to match a character that isn't in a predetermined set. The question:

Is there any way to exclude certain strings (or preferably certain regexps) from matching? On the edge of my brain I feel like this might not be possible because parsing for regexps NOT to match could quickly escalate the processing time to unacceptable levels.

The exact thing I want to do is skip ahead in my httpd log file to the first occurrence of a request that isn't from 'coffman'. So, in other words, I'm looking for the first line that starts with a word (\w*) that != coffman. How would you go about this?

BTW, I am doing this in Vi, so I'm not sure how Perl-y the regexps are (heck, I don't even fully understand the differences between POSIX and Perl Regexps).

-jiblet

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 10-03-2001 22:18

In newer versions of PERL, regular expressions have support for lookbehind & lookahead assertions, which in combination with multiline modifier can probably do what you want (but not in Vi)... Here's a brief explanation of lookbehind assertions (copy pasted from PCRE manual):

Lookbehind assertions start with (?<= for positive assertions and (?<! for negative assertions. For example,

(?<!foo)bar

does find an occurrence of "bar" that is not preceded by "foo". The contents of a lookbehind assertion are restricted such that all the strings it matches must have a fixed length. However, if there are several alternatives, they do not all have to have the same fixed length.

hyperbole
Paranoid (IV) Inmate

From: Madison, Indiana, USA
Insane since: Aug 2000

posted posted 10-04-2001 06:20

jiblet: You say you are doing this in VI. Why don't you use :g/^coffman\>/d to delete all lines in the file that start with the word 'coffman'.




hlaford
Bipolar (III) Inmate

From: USA! USA! USA!
Insane since: Oct 2001

posted posted 10-10-2001 22:28

Since your logic is fairly simple, you needn't worry about negative look-aheads and all that stuff:

code:
if(!/^coffman/i.test(lineFromLog)){
// do your processing
}




jiblet
Paranoid (IV) Inmate

From: Minneapolis, MN, USA
Insane since: May 2000

posted posted 10-15-2001 15:53

OOpz, my response never made it.

That is a great idea hyperbole, and in fact I did do that.

hlaford- I was actualy doing this in Vi, so writing code is not a viable solution. Actually I posted the question on more of a theoretical level... the problem itself was rather inconsequential, I probably would have done just what you suggested if I needed to automate this process somehow.

-jiblet

« BackwardsOnwards »

Show Forum Drop Down Menu