Regex for strings utility

Steve Holden sholden at holdenweb.com
Tue Jul 17 15:25:59 EDT 2001


rhys tucker" <rhystucker at yahoo.com> wrote in message
news:1103_995396879 at pan...
> I'm trying to write a script which operates like the Unix 'strings'
utility but I'm having difficulties with the regex.
>
> #!/usr/bin/env python
>
> # strings program
>
> import sys, re
>
> f = open(sys.argv[1])
> line = f.readline()
> pattern = ([\040-\126\s]{4,})
>
> while line:
> # regular expression to match strings >=4 chars goes here
> matches = findall(pattern, line)
> for match in matches;
> print match
> line = f.readline()
>
>
>
> I'm getting a Syntax Error: Invalid Token at the closing brace to the
pattern.
>
Try

pattern = "([\040-\126\s]{4,})"

for a start.  I notice you import re, but don't use it anywhere - your
findall() call could be re.findall(), perhaps?

I'm not a regex guru, but I have my doubts that the pattern will match what
you want it to. Perhaps the effbot or one of his proxies could advise...

regards
 Steve

--
http://www.holdenweb.com/








More information about the Python-list mailing list