0

I need to check multiple regexp in one string. Is it possible to check in one regexp? Here is important to find any order of words.

For example I looking for "quick", "jump" "lazy" in the string.

I can check it with OR operator. It working with | (pipe) character. But how can I change the OR to AND ?

I can use this with OR:

/quick|jump|lazy/

But I want to use something like this:

/quick&jump&lazy/

Is there any way?

netdjw
  • 5,419
  • 21
  • 88
  • 162
  • So basically you want to match, what, a line in a string containing those words? Because `quick|jump|lazy` is **one** match, so the OR operator is pretty explicit here. A AND operator wouldn't be, as it would imply multiple matches. – Kilazur May 27 '14 at 10:19
  • @Kilazur I want to match two or more words in a string. And I want to match only if every words are in the strings. – netdjw May 27 '14 at 10:24

1 Answers1

5

/(?=.*quick)(?=.*jump)(?=.*lazy)/ is what you're looking for I believe

David
  • 7,028
  • 10
  • 48
  • 95
  • Yes, you're right. I fixed it. – David May 27 '14 at 10:25
  • @CasimiretHippolyte Even with the `.*` thrown in, this will only match words in the given order, i.e. it will match `the quick brown fox jumps over the lazy dog`, but it won't match `over the lazy dog jumps the quick brown fox` – Frank Schmitt May 27 '14 at 10:26
  • 1
    @FrankSchmitt: No, you don't have problems of order, since you use zero-width assertions. Each words can be everywhere in the string (test it) – Casimir et Hippolyte May 27 '14 at 10:27
  • @CasimiretHippolyte I stand corrected - I thought you talked about putting the `.*` between the matching groups, sorry. – Frank Schmitt May 27 '14 at 10:29