add 'text.extr()'
a stripped-down version of text.extract() that - always returns a string (like 'extract_from') - only returns a string - does not deal with 'pos' arguments - is ~20% faster
This commit is contained in:
@@ -120,6 +120,15 @@ def extract(txt, begin, end, pos=0):
|
||||
return None, pos
|
||||
|
||||
|
||||
def extr(txt, begin, end):
|
||||
"""Stripped-down version of 'extract()'"""
|
||||
try:
|
||||
first = txt.index(begin) + len(begin)
|
||||
return txt[first:txt.index(end, first)]
|
||||
except (ValueError, TypeError, AttributeError):
|
||||
return ""
|
||||
|
||||
|
||||
def rextract(txt, begin, end, pos=-1):
|
||||
try:
|
||||
lbeg = len(begin)
|
||||
|
||||
Reference in New Issue
Block a user