I want to do a simple string match, searching from the -front- of the string. Are there easier ways to do this with maybe a builtin? (re seems like overkill)
def matchStr(ipadr = '10.20.30.40', matchIP = '10.20.'):
if ipadr[0:len(matchIP)] == matchIP: return True
return False
def matchStr(ipadr = '10.20.30.40', matchIP = '10.20.'):
return ipadr.startswith(matchIP)
>>> 'abcde'.startswith('abc')
True
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With