regexp logic and or

If it contains earth AND world, it contains one after the other, so:

earth.*world|world.*earth

A shorter alternative (using extended regex syntax) would be:

/^(?=.*?earth)(?=.*?world)/

But it is not at all like an and operator. You can only do or because if only one of the words is included, there is no ordering involved. If you want to have them both, you need to indicate the order.

Leave a Comment