Limits on search length

Paul Hankin paul.hankin at gmail.com
Mon Oct 1 18:24:44 EDT 2007


On Oct 1, 6:16 pm, Daryl Lee <d... at altaregos.com> wrote:
> I am trying to locate all lines in a suite of files with quoted strings of
> particular lengths.  A search pattern like r'".{15}"' finds 15-character
> strings very nicely.  But I have some very long ones, and a pattern like
> r'".{272}"' fails miserably, even though I know I have at least one
> 272-character string.
>
> In the short term, I can resort to locating the character positions of the
> quotes, but this seemed like such an elegant solution I hate to see it not
> work.  The program is given below (sans imports), in case someone can spot
> something I'm overlooking:
>
> # Example usage: search.py *.txt \".{15}\"
> filePattern = sys.argv[1]
> searchPattern  = sys.argv[2]
> cpat = re.compile(searchPattern)

Most shells will expand *.txt to the list of files that match, so
you'll end up with the first .txt file as your 'filePattern', and the
second as the regexp. Could that be it?

--
Paul Hankin




More information about the Python-list mailing list