Is there any way to get permutation of all words in a string using only regular expression in php.
For example:
for input like "How to remove pain in human knee"
I want output as:
"How To", "How","pain knee","remove knee","knee pain","in remove","human pain knee", etc.
Using regex will only serve to slow down the process.
I have written a function based on the
powerSet()
function posted by Yada @ https://stackoverflow.com/a/27968556/2943403)Code: (Demo)
Output:
Here is a post by bob at math.stackexchange which confirms that
13699
is the expected size of the returned array when given7
words in the input string. Furthermore, bob's breakdown should serve as a warning about how the permutations ramp up rather fast -- be careful with your big strings.