If you want all the possible permutation of letters from abc
, 123
and ()
, and that they are not allowed to be together, then you can use following regex:
var reg = /[abc]{3}|[123]{3}|[()]{2}/;
//This will match aaa, abc, bbb, bca, ccc, 123, 213, (), )( , etc...
https://regex101.com/r/44YoW8/2
Based on OP's comment in @Kobe's answer, (s)he wants any combination of abc , 123 and ().
You can use the following regex if you just want these kind of characters, namely a, b, c, 1, 2, 3, (, and ) with any number of these letters, you can use :
/[abc123()]*/
For checking if the given string matches the regex
To test, you need to test whether the returned value of the match function is equal to the actual string. Consider following code:
test1 = "abcd";
test2 = "abc";
reg = /abc/;
if (test1 == test1.match(reg)) console.log("test1 matched"); //it won't be printed as it doesn't matches completely
if (test2 == test2.match(reg)) console.log("test2 matched"); //this would be printed.
But, if you want permutation of these letters, numbers and symbols without change in number of kind, then I don't think regex will help. See Regex permutations without repetition.
But you can write a simple function for this checking easily.