String Matching

david brochu jr brochu121 at
Fri Mar 31 22:13:39 CEST 2006


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 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():
   print "Found", x


for x in search:

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

I get the error message:

Traceback (most recent call last):
  File "C:\Python24\scripts\PII\search
  File "C:\Python24\scripts\PII\search
    regexp = re.compile(x)
  File "C:\Python24\lib\", line
    return _compile(pattern, flags)
  File "C:\Python24\lib\", 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: <>

More information about the Python-list mailing list