Quote:
> The regexp [^f] matches any charecter exept "f" , i.e. "f" is
> avoided. Now: I want to avoid "foo", but [^foo] doesn't do the
> job. So how do I avoid "foo" ( or a string ) in regexp ??
I assume that some character (say \000) is guaranteed not to occur
in the input. Then it can be done as follows:
To replace every "bar" by "baz", unless it is followed by "foo":
s/(bar)/$1\000/g; # Put a marker after every bar.
s/\000(foo)/$1/g; # Remove the marker, if followed by foo.
s/bar\000/baz/g; # Replace every bar that is still followed
# by a marker.
To replace every "bar.*foo" by "baz", where the string that is matched
by '.*' does not contain any "foo":
s/(foo)/\000$1/g; # Put a marker before every foo.
s/bar[^\000]*\000foo/baz/g; # Replace every bar[<nomarker>]*<marker>foo .
s/\000//g; # Remove remaining markers.
To check whether $_ contains some "bar" that is not (immediately)
followed by "foo":
s/(bar)/$1\000/g; # Put a marker after every bar.
s/\000(foo)/$1/g; # Remove the marker, if followed by foo.
m/\000/; # Check whether there is a marker left.
Another possibility:
s/barfoo/foo/g; # Remove every bar that is followed by foo.
m/bar/; # Check whether there is a bar left.
Note that the following command _does_something_different_:
m/bar/ && ! m/barfoo/; # Check that there is a bar and that
# *no* bar is followed by foo.
It will fail if the input contains both a bar that is followed by foo
and a bar that is *not* followed by foo.
--
Uwe Waldmann, Max-Planck-Institut fuer Informatik
Im Stadtwald, D-66123 Saarbruecken, Germany