I tried /^[^(xyz)]/ but I don't trust it. I don't think the grouping
will take inside the character class.
The [^(xyz)] creates a negative character class, so your regex would
match any string that started with a character not in the given set.
Not what you really want
Do I need a negative lookahead assertion?
That would be a simple solution: /^(?!xyz)/ which will match when
the beginning of the line/string is not followed by 'xyz'.
andrew
···
On Wed, 29 Mar 2006 03:24:36 +0900, Wes Gamble <weyus@att.net> wrote:
--
Andrew L. Johnson http://www.siaris.net/
What have you done to the cat? It looks half-dead.
-- Schroedinger's wife
On Wed, 29 Mar 2006 03:24:36 +0900, Wes Gamble <weyus@att.net> wrote:
I tried /^[^(xyz)]/ but I don't trust it. I don't think the grouping
will take inside the character class.
The [^(xyz)] creates a negative character class, so your regex would
match any string that started with a character not in the given set.
Not what you really want
Do I need a negative lookahead assertion?
That would be a simple solution: /^(?!xyz)/ which will match when
the beginning of the line/string is not followed by 'xyz'.
Uhm, maybe I've misunderstood (wouldn't be the first time) -- I thought you
wanted to match strings that did not begin with 'xyz' ... and as far as I
can tell, "29384723xyz02342" does not start with 'xyz'.
while DATA.gets
print if ~/^(?!xyz)/
end
__END__
xyefoo
xyzpfoo
asdfsdf
1230xyzasdf
produces:
xyefoo
asdfsdf
1230xyzasdf
puzzled,
andrew
···
On Wed, 29 Mar 2006 03:43:51 +0900, Wes Gamble <weyus@att.net> wrote:
In my example, won't /^(?!xyz)/ also match
29384723xyz02342
which is a little more than I want?
--
Andrew L. Johnson http://www.siaris.net/
People seem not to see that their opinion of the world is
also a confession of character.
-- Ralph Waldo Emerson; The Conduct of Life, 1860
In actuality, I do need the ability to pass one regex to do the job into
another utility that will use it to operate on an array of strings.
So although !~ is cool, I really didn't want to have to iterate through
the strings myself.
Thanks,
Wes
Andrew Johnson wrote:
···
On Wed, 29 Mar 2006 03:43:51 +0900, Wes Gamble <weyus@att.net> wrote:
In my example, won't /^(?!xyz)/ also match
29384723xyz02342
which is a little more than I want?
Uhm, maybe I've misunderstood (wouldn't be the first time) -- I thought
you
wanted to match strings that did not begin with 'xyz' ... and as far as
I
can tell, "29384723xyz02342" does not start with 'xyz'.
while DATA.gets
print if ~/^(?!xyz)/
end
__END__
xyefoo
xyzpfoo
asdfsdf
1230xyzasdf
Now I want to match any line that doesn't have "xyz" or "abc" at the
beginning of the line.
Is there a way to "AND" together the input to the negative lookahead
assertion?
Wes
Wes Gamble wrote:
···
Andrew,
That works fine.
In actuality, I do need the ability to pass one regex to do the job into
another utility that will use it to operate on an array of strings.
So although !~ is cool, I really didn't want to have to iterate through
the strings myself.
Thanks,
Wes
Andrew Johnson wrote:
On Wed, 29 Mar 2006 03:43:51 +0900, Wes Gamble <weyus@att.net> wrote:
In my example, won't /^(?!xyz)/ also match
29384723xyz02342
which is a little more than I want?
Uhm, maybe I've misunderstood (wouldn't be the first time) -- I thought
you
wanted to match strings that did not begin with 'xyz' ... and as far as
I
can tell, "29384723xyz02342" does not start with 'xyz'.
while DATA.gets
print if ~/^(?!xyz)/
end
__END__
xyefoo
xyzpfoo
asdfsdf
1230xyzasdf