I guess I'm getting really weak in logic.
I need to write a regular expression which matches everything except www. It should match wwwd, abcd and everything else, just not www. (Oh God, please, it shouldn't be very easy).
I'm using Ruby language's implementation of regular expression.
UPDATE: I need to use regular expression and not just text != 'www' because it is the way API is designed. It expects a pattern as argument and not the result.
Why regex? Isn't text != "www" enough?
Here it is nonetheless (uses look-ahead): ^(?!www$).*
This is a plain vanilla regex. There are fancier things you can do with negative assertions in certain dialects.
^(.|..|[^w]..|.[^w].|..[^w]|.....*)$
In English:
You want something that's exactly one character, exactly two characters, exactly three characters where at least one of those 3 is not a w, or more than 3 characters long.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With