I need only line (1) and (3) by the keyword "a" "b" and "c" by regular expression and javascript.
Text is:
a+b+c (1)
test+a+test (2)
c+b+a(3)
test+b+test (4)
I found "(?=.*a).*b". But how can I do with more than 2 keywords like the example?
I need only line (1) and (3) by the keyword "a" "b" and "c" by regular expression and javascript.
Text is:
a+b+c (1)
test+a+test (2)
c+b+a(3)
test+b+test (4)
I found "(?=.*a).*b". But how can I do with more than 2 keywords like the example?
You can use positive lookahead assertions as in the following regex to match the required text:
/^(?=.*a)(?=.*b)(?=.*c)/
More details about lookahead and lookbehind can be found here: Regex lookahead, lookbehind and atomic groups
JavaScript Demo
var a = "a+b+c";
var b = "test+a+test";
var c = "c+b+a";
var d = "test+b+test";
var pattern = /^(?=.*a)(?=.*b)(?=.*c)/;
console.log(a + " ----- " + pattern.test(a));
console.log(b + " ----- " + pattern.test(b));
console.log(c + " ----- " + pattern.test(c));
console.log(d + " ----- " + pattern.test(d));