Skip to content

Instantly share code, notes, and snippets.

@vicalejuri
Created November 4, 2009 17:58
Show Gist options
  • Save vicalejuri/226244 to your computer and use it in GitHub Desktop.
Save vicalejuri/226244 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import re,sys
def searchInArray( shit, likeStr ):
escape_chars = list( '.^$*+?()[{\\' )
op_chars = list( '%_' )
safe_re = "".join( map( lambda c: c in escape_chars and ('\\' +c) or c , likeStr ) )
match_re = "".join( map( lambda c: c == op_chars[0] and ('.*?') or (c == op_chars[1] and '.' or c) , safe_re ) )
match_re = (not match_re[0] in op_chars and '^' or '') + match_re + (not match_re[-1] in op_chars and '$' or '')
return map( lambda s: re.match( match_re, s) != None and True or False, shit )
teste = ['rafael','gabriel','marcelo','coco']
print searchInArray( ['rafael','gabriel','marcelo','coco'] , sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment