Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Case insensitive Find

Posted on 2006-06-21
4
Medium Priority
?
547 Views
Last Modified: 2012-06-21
Python is used to parse report text. Text between certain keywords are stored to Db. Like:

value = reportText[(reportText.find('FINDINGS:'))+9:reportText.find('IMPRESSION:')]
value = value.rstrip()
value = value.lstrip()

Is used to get the text between the FINDINGS: and IMRESSION: and later, store the text in the findings column. I cannot get the other party to protect the report template or send me the data pre-parsed. Often someone will change FINDINGS: to Findings: which breaks the above. I must preserve the case of the reportText.

How can I accomplish the same parsing task but make it so the find is case insensitive?  
0
Comment
Question by:acave
  • 2
4 Comments
 
LVL 17

Accepted Solution

by:
ramrom earned 1200 total points
ID: 16956094
reportText.upper().find('FINDINGS:')
0
 
LVL 15

Assisted Solution

by:mish33
mish33 earned 300 total points
ID: 16956913
def get_from_report(rpt):
  import re
  m = re.match(r'FINDINGS:\s*(.?*)\s*IMPRESSION:', rpt, re.IGNORECASE)
  if m:
    return m.group(1)

>>> print get_from_report(findings: abc impression:')
abc
0
 
LVL 15

Expert Comment

by:mish33
ID: 16956921
Correction: use re.search instead of re.match
0
 

Author Comment

by:acave
ID: 16971768
Thanks ramrom, love simplicity. Thanks mish33, got me thinking about encapsulation and reuse. I combined your answers to build a good solution.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The really strange introduction Once upon a time there were individuals who intentionally put the grass seeds to the soil with anticipation of solving their nutrition problems. Or they maybe only played with seeds and noticed what happened... Som…
Sequence is something that used to store data in it in very simple words. Let us just create a list first. To create a list first of all we need to give a name to our list which I have taken as “COURSE” followed by equals sign and finally enclosed …
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Suggested Courses

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question