javascript – anagrams can be handled with regexp

No

A regexp will not formulate the various anagrams, as originally askedbbybthe question.

Yes it could recognise anagrams, if the conditions are simple

There is an excellent answer below by @blhsing showing how to do it in your simple case.

It will be more difficult for general anagrams, e.g. If the user is allowed to input the requirements and they may involve repeated characters. At that stage you may wish to use a different approach.

Alternative approach

Keep a dictionary containing a running total of characters found.

Once you get to the number of characters in your requirement string, 3, compare the dictionary with a pre prepared dictionary for the requirement string.

For every onward step, update the running dictionary with the character that you are now adding, and the character that you are now subtracting (3 characters to the left, in your case)

That way at each step you can compare with the dictionary of the requirement and if there is a match, print it.

Read more here: Source link