[Tutor] regex question
Richard D. Moores
rdmoores at gmail.com
Tue Jan 4 21:02:07 CET 2011
On Tue, Jan 4, 2011 at 11:57, Richard D. Moores <rdmoores at gmail.com> wrote:
> On Tue, Jan 4, 2011 at 10:41, Richard D. Moores <rdmoores at gmail.com> wrote:
>> Please see http://tutoree7.pastebin.com/z9YeSYRw . I'm actually
>> searching RTF files, not TXT files.
>>
>> I want to modify this script to handle searching on a word. So what,
>> for example, should line 71 be?
>
> OK, I think I've got it.
>
> in place of lines 66-75 I now have
>
> search = input("first search string: ")
> search = "\\b" + search + "\\b"
> if not search:
> print("Bye")
> sys.exit()
> elif search[0] != ' ':
> p = re.compile(search, re.I)
> else:
> p = re.compile(search)
Oops. That should be
search = input("first search string: ")
if not search:
print("Bye")
sys.exit()
elif search[0] != ' ':
search = "\\b" + search + "\\b"
p = re.compile(search, re.I)
else:
search = "\\b" + search + "\\b"
p = re.compile(search)
Dick
More information about the Tutor
mailing list