How to display all words that contain these characters?

后端 未结 7 1852
后悔当初
后悔当初 2021-01-03 00:05

I have a text file and I want to display all words that contains both z and x characters.

How can I do that ?

7条回答
  •  醉梦人生
    2021-01-03 00:27

    >>> import re
    >>> print re.findall('(\w*x\w*z\w*|\w*z\w*x\w*)', 'axbzc azb axb abc axzb')
    ['axbzc', 'axzb']
    

提交回复
热议问题