>> i've to exclude the "connector" string, so i need a regexp that gives
>> true on "my head is broken", and false on "my connector is broken",
[quoted text clipped - 12 lines]
> System.out.println( s +(lacksConnector? " does " : " does not ")
> +"contain \"connector\"." );
Check out what the OP wrote earlier... He's got preexiting logic which
uses a regex, wants to change but the regex and leave the rest intact.
I don't think what the OP intends is feasible. That's not quite what
regexes are for: matching the absence of something. Indeed, why should
they, when it is so easy to match the presence of something and then
negate the result. But he'll have to change the logic for that, and I'm
afarid the OP has no other option.
Oliver Wong - 20 Jun 2007 23:14 GMT
>>> i've to exclude the "connector" string, so i need a regexp that gives
>>> true on "my head is broken", and false on "my connector is broken",
[quoted text clipped - 21 lines]
> negate the result. But he'll have to change the logic for that, and I'm
> afarid the OP has no other option.
It's certainly possible, but painful.
The proof that it's possible is that it's fairly simple to draw a
finite state machine (FSM) which accepts all strings which do not contain
"connector", and reject all strings that do, and it's always possible to
convert a FSM into a regular expression. But it's painful to write. It'd
look something like:
(anything except 'c')
OR "c" followed by (anything except 'o')
OR "co" followed by (anything except 'n')
and so on.
- Oliver