If you are looking for all the different combinations of letters from abc
, 123
, and ()
, but you do not want them to be grouped together, you can utilize the following regular expression:
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 the OP's comment in @Kobe's answer, they want any combination of abc, 123, and ().
If you only want to allow these specific characters (a, b, c, 1, 2, 3, (, and )) with any quantity of them, you can use the following regex:
/[abc123()]*/
To check if a given string matches the regex pattern:
To test this, you can compare the returned value from the match function with the actual string. Here is an example:
test1 = "abcd";
test2 = "abc";
reg = /abc/;
if (test1 == test1.match(reg)) console.log("test1 matched"); //This will not be printed as it does not match completely
if (test2 == test2.match(reg)) console.log("test2 matched"); //This will be printed
However, if you want permutations of these letters, numbers, and symbols without changing the quantity of each, regex may not be the best solution. You can refer to Regex permutations without repetition. Alternatively, you can easily create a simple function to handle this kind of checking.