PDA

View Full Version : Regular Expression Question



gab10
February 13th, 2005, 08:04 PM
I'm not too good with Regular Expressions... does anyone know the syntax to find all the strings that don't contain a particular phrase? I tried

(somephrase){0}
but that doesn't seem to work.

Koobi
February 14th, 2005, 02:57 PM
I'm not too good with Regular Expressions... does anyone know the syntax to find all the strings that don't contain a particular phrase? I tried

(somephrase){0}
but that doesn't seem to work.
This should work.



[^somephrase]+

ow50
February 14th, 2005, 06:48 PM
This should work.

[^somephrase]+
Wouldn't that would equal
[bcdfgijklnqtuvwxyz]+which would match lines that have at least one character not in 'somephrase'?


I dont know of a way to match not 'somephrase' with standard regexes. It depends on what app you're using.

Grep:
grep -Gv "somephrase" filename

Perl script:

while (<FILE>) {
if ($_ !~ /somephrase/ ) { print "$_" }
}

Sed seems to have ! as negation operator, but I don't know how to use that.