[Zope] FindOneOf?

Patrick Lewis pl@teleport.com
Thu, 27 Jul 2000 14:40:32 -0700


In a Python external method:

import re

def FindOneOf(to_find, search_str):
    match_obj = re.search("[%s]" % to_find, search_str)
    if match_obj:
        return match_obj.start() + 1
    else:
        return 0

So, calling FindOneOf("ghd", "abcdefghij") returns 4.  This will work as
is unless searching for a '-' (which will work ok as long as it is at the
start of to_find).

Not quite sure what the third argument 1 is for in the ColdFusion
version, so say something if it is important.

On Thu, Jul 27, 2000 at 03:44:54PM -0400, Mabe, Brad wrote:
> ColdFusion (I know, a dirty word ;-) ) has a nifty string function called
> "FindOneOf" which returns the index of the occurrence of any character in a
> string.
> 
> Example:
>  FindOneOf("ghd", "abcdefghij", 1) 
> 
> Will return a "4" because "d" is the fourth letter in the string
> "abcdefghij".  If no match is made, a 0 is returned.  This is especially
> useful when building a change password form, because I can easily check to
> see that the new password contains at least one special character, upper
> case character, number, etc.  Is there anything similar to FindOneOf in
> ZOPE?  If not, does anyone have any hints on how I can go about doing this
> kind of thing through dtml or python?
> 
>         -=Brad=-

-- 
Patrick Lewis <pl@teleport.com>