Created
November 4, 2009 17:58
-
-
Save vicalejuri/226244 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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