开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜