def to_rest(openflow): if REST_ACTION in openflow: actions = [] for action in openflow[REST_ACTION]: field_value =re.seach('SET_FIELD: {ip_dscp:(\d+)', action) if field_value: actions.append({REST_ACTION_MARK: field_value.group(1)}) if field_value: actions.append({REST_ACTION_MARK: field_value.group(1)}) meter_value = re.search('METER:(\d+)', action) if meter_value: actions.append({REST_ACTION_METER: meter_value.group(1)}) if queue_value: actions.append({REST_ACTION_QUEUE: queue_value.group(1)}) action = {REST_ACTION: action} else: action = {REST_ACTION: 'Unknown action type'} return action
def parse(self, string): if re.search(osFamily.WINDOWSSERVER.family.partition(" ")[0], string, re.IGNORECASE) and re.seach(osFamily.WINDOWSSERVER.family.partition(" ")[1], string, re.IGNORECASE): return osFamily.WINDOWSSERVER elif re.search(osFamily.WINDOWS.family, string, re.IGNORECASE): return osFamily.WINDOWS elif re.search(osFamily.UBUNTUSERVER.family.partition(" ")[0], string, re.IGNORECASE) and re.search(osFamily.UBUNTUSERVER.family.partition(" ")[1], string, re.IGNORECASE): return osFamily.UBUNTUSERVER elif re.search(osFamily.UBUNTU.family, string, re.IGNORECASE): return os.Family.UBUNTU elif re.search(osFamily.MACSERVER.family.partition(" ")[0], string, re.IGNORECASE) and re.search(osFamily.MACSERVER.family.partition(" ")[1], string, re.IGNORECASE) and re.search(osFamily.MACSERVER.family.partition(" ")[2], string, re.IGNORECASE): return os.Family.MACSERVER elif e.search(osFamily.MACSERVER.family.partition(" ")[0], string, re.IGNORECASE) and re.search(osFamily.MAC.family.partition(" ")[1], string, re.IGNORECASE): return os.Family.MAC
import re value=[] items=[x for x in input("nhap mat khau: ").split(',')] # ########## for p in items: if len(p)<6 or len(p)>12: continue else: pass if not re.search("[a-z]",p): continue elif not re.search("[0-9]",p): continue elif not re.search("[A-Z]",p): continue elif not re.seach("[$#@]",p): continue elif re.search("\s",p): continue else: pass value.append(p) print(",".join(value))
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license()" for more information. >>> import re >>> p='hello' >>> t = 'hi hello' >>> re.search(p, t) <re.Match object; span=(3, 8), match='hello'> >>> m = re.seach(p,t) Traceback (most recent call last): File "<pyshell#4>", line 1, in <module> m = re.seach(p,t) AttributeError: module 're' has no attribute 'seach' >>> m = re.search(p,t) >>> type(m) <class 're.Match'> >>> m.start(), m.end() (3, 8) >>> t[m.start():m.end()] 'hello' >>> p='hello' >>> t = 'hello hi hello' >>> m = re.search(p,t) >>> m.start(), m.end() (0, 5) >>> re.findall(p,t) ['hello', 'hello'] >>> for m in re.finditer(p,t): print("found at: ", m.start(), m.end()) found at: 0 5
import re value=[] items=[x for x in input('nhap mat khau: ').split(',')] for p in items: if len(p)<6 or len(p)>12: continue else: pass if not re.seach('[a-z]', p): continue elif not re.seach('[0-9]', p): continue elif not re.seach('[A-Z]', p): continue elif not re.seach('[$#@]', p): continue elif not re.seach('[\s]', p): continue else: pass value.append(p) print(','.join(value))