string - longest match in python -
i new in python.i have data in 2d- array in following format.
array[0] array[1] arkan adrian edmondson efgan rik 'til death part (star trek: deep space nine) bradley thompson 'til death part (star trek: deep space nine) david weddle billy sherrill 'til can make on own (deep space) i want match string each line in file, if matches both array want return line. first, want search both array in each line .for attempt was:
def strinmach(domainl, ranger): text = "" filetext = open(file, "r").read() sentlist = re.split(u'[\n|\r\n]+',filetext) in sentlist: if domainl in , ranger in i: text = text + + "\n" elif (to search without parenthesis string array[0] & array[1] eg.search (til death part bradley thompson ) ) elif (to search string array[0] & array[1] es. search with(till death bradley) or (do part thompson)) return text my second step seraching array except parenthesis string (i.e except (terms) ).
and third step substring of both array.
how proceed on 2nd & 3rd step.
any kind of appreciated. thanks!!!!!!!
i'm having bit of trouble working out you're asking, maybe help:
you can remove bracketed section of string with:
thetext = re.sub(r"\(.*?\)", "", thetext) (n.b. won't work if have "((nested) brackets)")
you can substrings slicing:
thetext[4:10] thetext[:5] # first 5 characters thetext[-5:] # last 5 characters thetext[:-1] # last character
Comments
Post a Comment