1

I'm rubbish at regular expressions, so would someone be able to help me find:

In a string at least one occurrence of of two other strings.

For example looking for the strings foo and bar:

foo foo bar: true

bar: false

foo bar: true

foo barfoo: true

foobar bar: true

foo ba: false

foo foo bar bar: true

Thank you all in advance!

1 Answer 1

1
/^(?=.*foo)(?=.*bar).*$/.test("foo bar");

and if you want to match whole words and not fragments :

/^(?=.*\bfoo\b)(?=.*\bbar\b).*$/.test("foo bar");
Sign up to request clarification or add additional context in comments.

1 Comment

As always, that's so close to what I had! Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.