Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
60
rated 0 times [  64] [ 4]  / answers: 1 / hits: 76540  / 14 Years ago, thu, march 3, 2011, 12:00:00

I know there are logical operators such as | the OR operator which can be used like this:



earth|world


I was wondering how I could check if my string contains earth AND world.



regards,
alexander


More From » regex

 Answers
73

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.


[#93480] Wednesday, March 2, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
daja

Total Points: 407
Total Questions: 103
Total Answers: 103

Location: Ghana
Member since Sun, Mar 27, 2022
2 Years ago
daja questions
Tue, Dec 21, 21, 00:00, 2 Years ago
Thu, Apr 23, 20, 00:00, 4 Years ago
Fri, Sep 6, 19, 00:00, 5 Years ago
Tue, Jul 23, 19, 00:00, 5 Years ago
;