Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] Regexp



>>>>> "Daniel" == Daniel Quimper <dq@example.com> writes:

    Daniel> I looking for a regular expression that would match
    Daniel> everything except a particuliar string.

Taking your egrep example seriously (ie, line-oriented behavior)

^[^a]*(a+([^ab][^a]*|b[^ac][^a]*)?)*$

should work.  Note that this only works because the first character is
different from both the second and the third, things are more
complicated if you have to worry about possibly matching the string
partially internally to itself.  The two-character negated classs
[^ab] and [^ac] do need to include 'a' so that the a+ eats all the
'a's in a row: a+[^b][^a]* does match "aabc": the first 'a' matches
a+, the second 'a' matches [^b], and 'bc' matchs [^a]*.  Similarly
a+b[^c][^a]* matches "ababc".  (That should give the flavor of what is
meant by "possible partial internal match".)

    Daniel> Changing the software is not an option.

Maybe changing jobs is?  Life is too short to try to do this kind of
task with regexps.  The "abc" example is _easy_.

-- 
Institute of Policy and Planning Sciences     http://turnbull.sk.tsukuba.ac.jp
University of Tsukuba                    Tennodai 1-1-1 Tsukuba 305-8573 JAPAN
               Ask not how you can "do" free software business;
              ask what your business can "do for" free software.


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links