From a8d0d8ac8be5cd1702314e457b81a65d54d7c41b Mon Sep 17 00:00:00 2001 From: Rolux Date: Tue, 29 Apr 2008 14:55:52 +0200 Subject: [PATCH] fixing findString() --- oxutils/text.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/oxutils/text.py b/oxutils/text.py index 4d4694a..450f6ee 100644 --- a/oxutils/text.py +++ b/oxutils/text.py @@ -5,15 +5,19 @@ import re def findRegexp(string, regexp): - result = None - regexp = re.compile(regexp, re.DOTALL) - match = regexp.search(string) - if match: - result = match.group(1) - return result + print string, regexp + return re.compile(regexp, re.DOTALL).findall(string) def findString(string, string0, string1 = ''): - return findRegexp(string, re.escape(string0) + '(.*?)' + re.escape(string1)) + string0 = re.escape(string0) + if string1: + string1 = re.escape(string1) + else: + string1 = '$' + result = findRegexp(string, string0 + '(.*?)' + string1) + if result: + return result[0].strip() + return None # Capitalizes the first letter of a string. capfirst = lambda x: x and x[0].upper() + x[1:]