Skip to content

Instantly share code, notes, and snippets.

@parthpower
Last active December 20, 2015 23:44
Show Gist options
  • Save parthpower/4cdb7f5510aaa948cd80 to your computer and use it in GitHub Desktop.
Save parthpower/4cdb7f5510aaa948cd80 to your computer and use it in GitHub Desktop.
Function to get string between start identifier and end identifier string.
#Released under MIT license.
__author__ = 'Parth Parikh'
__license__ = 'MIT'
def find_by_identifier(data,startIdentifier,endIdentifier):
result = []
identLen = len(startIdentifier)
##First check
##print(identLen)
startIdentIndex = -1
startIdentIndex = data.find(startIdentifier,startIdentIndex+1)
endIdentIndex = data.find(endIdentifier,startIdentIndex+identLen)
if endIdentIndex == -1:
return []
while startIdentIndex!=-1:
#print("%d-%d"%(startIdentIndex,endIdentIndex))
result.append(data[startIdentIndex+identLen:endIdentIndex])
#print(data[startIdentIndex+identLen:endIdentIndex])
startIdentIndex = data.find(startIdentifier,startIdentIndex+1)
endIdentIndex = data.find(endIdentifier,startIdentIndex+identLen)
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment