regex (?!..) problem
Hans Mulder
hansmu at xs4all.nl
Tue Oct 6 15:12:39 EDT 2009
Stefan Behnel wrote:
> Wolfgang Rohdewald wrote:
>> I want to match a string only if a word (C1 in this example) appears
>> at most once in it.
>
> def match(s):
> if s.count("C1") > 1:
> return None
> return s
>
> If this doesn't fit your requirements, you may want to provide some more
> details.
That will return a false value if s is the empty string.
How about:
def match(s):
return s.count("C1") <= 1
-- HansM
More information about the Python-list
mailing list