asking

Terry Reedy tjreedy at udel.edu
Wed Aug 22 01:42:09 EDT 2012


On 8/21/2012 10:57 PM, mingqiang hu wrote:
>   can I use just one statement to figure out if  substring “a” ,"b" "c"
> are in  string "adfbdfc" ?  not use the statement like
>
> ("a" in "adfbdfc")  or ( "b" in "adfbdfc") or ("c" in "adfbdfc" )
> ,because if I have lots of substring, this could sucks

 >>> import re
# single chars
 >>> print(re.search('[abc]', 'defgh'))
None
 >>> print(re.search('[abc]', 'defgha'))
<_sre.SRE_Match object at 0x0000000003251098>
# multichar strings
 >>> print(re.search('ab|ha]', 'defgha'))
None
 >>> print(re.search('ab|ha', 'defgha'))
<_sre.SRE_Match object at 0x0000000003251098>

-- 
Terry Jan Reedy





More information about the Python-list mailing list