I have some input string with characters and list of string. What I need is to select only strings that meet pattern that contains characters.
For excample:
input chars = “ask”
it should accept “ask”, “sak”, “kas”…
but should not accept “akk”, “aas”…
now I use pattern like “^[s|a|k][s|a|k][s|a|k]$”
but probablem with it that it accept and repeated characters (“akk”), so if I using this I need some additional check if preg_match works.
What it makes a bit more complicated, that there can be few same characters:
input “askk”
should match “akks”, but not “kkks” or “assk”.
I believe that this check can be done with single regexp, but my knowledge about regexp isn’t so deep.
(to get input and show resuls I use php)
Why using a regex here? I don’t see the benefit. What you could do is sort the input string (e.g. both ‘sak’ and ‘ask’ will turn into ‘aks’) and compare that sorted string to a reference string, ‘aks’ in this case. Or just use the same function on the reference string ‘ask’ as well. Something like this: