String Matching

david brochu jr brochu121 at gmail.com
Fri Mar 31 15:13:39 EST 2006


Hello,

I am trying to write a script that takes strings from a text file and
searches to see if they are present in another text file...here is the code:

import os
import re

search = open("c:\python24\scripts\pii\expected_rules_results.txt")

def find(x):
 file = open("c:\python24\scripts\pii\dave.txt")
 regexp = re.compile(x)
 for line in file.readlines():
  if regexp.search(line):
   print "Found", x
   break


 file.close()


for x in search:
 find(x)
search.close()



Unfortunately the strings I will be searching for contain numerous "*" that
cause an error. For example, when try to search for:

http://www.widget.com/personal_firewall.csp/?pin=****{6}

I get the error message:

Traceback (most recent call last):
  File "C:\Python24\scripts\PII\search
    find(x)
  File "C:\Python24\scripts\PII\search
    regexp = re.compile(x)
  File "C:\Python24\lib\sre.py", line
    return _compile(pattern, flags)
  File "C:\Python24\lib\sre.py", line
    raise error, v # invalid expressio
sre_constants.error: multiple repeat



Anyone know how to get around this?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20060331/23a80414/attachment.html>


More information about the Python-list mailing list