How to find if a string contains all the certain characters?
For example:
Characters to match: 'czk'
string1: 'zack' Matches
string2: 'zak' Does not match
I tried (c)+(k)+(z)
and [ckz]
which are obviously wrong. I feel this is a simple task, but i am unable to find a开发者_StackOverflow社区n answer
The most natural way would probably to use sets rather than regex, like so
set('czk').issubset(s)
Code is very often simpler and easier to maintain without using regex much.
Basically you have to sort the string first so you get "ackz" and then you can use a regex like /.*c.*k.*z.*/
to match against.
精彩评论