Solved

Case insensitive Find

Posted on 2006-06-21
4
542 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Here I am using Python IDLE(GUI) to write a simple program and save it, so that we can just execute it in future. Because when we write any program and exit from Python then program that we have written will be lost. So for not losing our program we…
Introduction On September 29, 2012, the Python 3.3.0 was released; nothing extremely unexpected,  yet another, better version of Python. But, if you work in Microsoft Windows, you should notice that the Python Launcher for Windows was introduced wi…
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 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 …

690 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