Solved

Case insensitive Find

Posted on 2006-06-21
4
524 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 400 total points
ID: 16956094
reportText.upper().find('FINDINGS:')
0
 
LVL 15

Assisted Solution

by:mish33
mish33 earned 100 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

"The time has come," the Walrus said, "To talk of many things: Of sets--and lists--and dictionaries-- Of variable kinks-- And why you see it changing not-- And why so strange are strings." This part describes how variables and references (see …
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

813 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now